当前位置: 代码迷 >> Sql Server >> 存储过程中执行 in (*),这个存储过程如何写
  详细解决方案

存储过程中执行 in (*),这个存储过程如何写

热度:80   发布时间:2016-04-27 20:16:37.0
存储过程中执行 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
  相关解决方案