22,209
社区成员
发帖
与我相关
我的任务
分享
declare @string1 varchar(max)
declare @c1 varchar(50)
set @c1='拉伸粘结强度'
set @string1 =
'if exists (select 1 from table1 where '+@c1+' in (''压折比''))
begin
select *
from table1 where '+@c1+' <= 3
end
else if exists (select 1 from table1 where '+@c1+' in (''拉伸粘结强度''))
begin
select *
from table1 where '+@c1+' >= 0.5
end'
print @string1
exec(@string1)
set @string1 =
'select *
from table1
where
case
when '+@c1+' in (''压折比'') then '+@c1+' <= 3
when '+@c1+' in (''拉伸粘结强度'') then '+@c1+' >= 0.5'
print @string1
exec(@string1)
declare @string1 varchar(max)
declare @c1 varchar(50)
set @c1='拉伸粘结强度'
set @string1 =
'select *
from table1
where
(case
when '+@c1+' in (''压折比'') then '+@c1+'- 3
when '+@c1+' in (''拉伸粘结强度'') then 0.5-'+@c1+'
end)<=0'
print @string1
exec(@string1)
-- 判断要创建的存储过程名是否存在
if exists (select * from sys.objects where name = 'proc1')
-- 删除存储过程
drop proc proc1
go
--存储过程proc1
create proc proc1
@c1 varchar(50)
as
--临时表
declare @string1 varchar(max)
set @string1 =
'select *
from table1
where
( '+@c1+' in (''压折比'') and '+@c1+' <= 3 ) or (
'+@c1+' in (''拉伸粘结强度'') and '+@c1+' >= 0.5)'
print @string1
GO
-- 判断要创建的存储过程名是否存在
if exists (select * from sys.objects where name = 'proc1')
-- 删除存储过程
drop proc proc1
go
--存储过程proc1
create proc proc1
@c1 varchar(50)
as
--临时表
declare @string1 varchar(max)
set @string1 =
'select *
from table1
where
case
when '+@c1+' in (''压折比'') then '+@c1+' <= 3
when '+@c1+' in (''拉伸粘结强度'') then '+@c1+' >= 0.5'
print @string1
GO
exec proc1 '拉伸粘结强度'