当前位置: 代码迷 >> Sql Server >> 怎的在存储过程中使用输入参数,然后用于 Where .In (@参数)
  详细解决方案

怎的在存储过程中使用输入参数,然后用于 Where .In (@参数)

热度:49   发布时间:2016-04-27 11:26:12.0
怎样在存储过程中使用输入参数,然后用于 Where ...In (@参数)
定义输入参数:
@InputID varchar(100)

比如可以输入:0001,0002,0003

然后使用
...
WHERE InputID IN (@InputID) //但是这个语句不管用!

我想实现的效果是:WHERE InputID IN (0001,0002,0003)


------解决方案--------------------
1)动态
exec('select * from tb where InputID IN ([email protected]+')')

调用
exec procname '''0001'',''0002'',''0003'''
2)
charindex 
select * from tb where charindex(','+ltrim(inputid)+',',',[email protected]+',')>0
------解决方案--------------------
create pro p_t @s varchar(100)
as
begin
exec('select * from tb where inputid in ([email protected] +')')
end
  相关解决方案