日期:2014-05-19  浏览次数:20456 次

存储过程中执行 in (*,*,*),这个存储过程怎么写?
一个存储过程,需要传入一个参数,在存储过程中执行   delete   from   table   where   id   in   (传入的参数),这个存储过程怎么写?id是int类型的。

------解决方案--------------------
改用CharIndex

delete from [table] where CharIndex( ', ' + Cast(id As Varchar) + ', ', ', ' + 传入的参数 + ', ') > 0

否則需要使用動態SQL語句
------解决方案--------------------
delete from [table] where charindex( ', '+rtrim(id)+ ', ', ', '+传入的参数+ ', ')> 0
------解决方案--------------------
delete from table where charindex( ', ' + rtrim(id) + ', ', ', ' + @idlist + ', ') > 0