如何在where条件中声明标量变量?

时间:2017-09-20 11:09:14

标签: sql function

我在函数中有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 

0 个答案:

没有答案