使用SQL语句进行删除操作有多种方法,下面为您介绍两种使用IN进行批量删除的方法,供您参考,希望对您能够有所帮助。

方法一:

如果需要用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