我在函数中有Scalar变量
@variable1 varchar(20)
现在,我想将查询框架为
select * from Table1 where columname ='Completed'
这里
'columname' is nothing but a @variable1. then , how to declare that??
我试过
select * from Table1 where @variable1='Completed'
但显示错误。
实施例
create function func(@variable1 varchar(10))
returns @tble Table(tble varchar(50) null)
as
begin
declare @SQL varchar(100)
set @SQL = 'select * from Table1 where '+@variable1+'IN (Completed)'
select @SQL
return
end