sql使用in批量删除 dodo

方法一:  
  如果需要用in的写法,就需要用到动态sql写,如下:  
    DECLARE   @ids   Varchar(50),@sql   varchar(8000)  
    set   @ids='3908,3934'--是从参数中得到字符   '3908,3934'  
    set   @sql   =   'delete   YH_order   WHERE   (id   IN   ('   +   @ids   +   '))'  
    --print   @sql     --   调试用  
    exec(@sql)  
   
  方法二:  
  其实这样的完全可以用charindex来解决,如下:   DECLARE   @ids   Varchar(50)  
    set   @ids='3908,3934'--是从参数中得到字符   '3908,3934'  
  delete   YH_order   WHERE   charindex(','   +   cast(id   as   varchar)   +   ',',','   +   @ids   +   ',')   >   0  

原文地址:https://www.cnblogs.com/zgqys1980/p/1452822.html