日期:2014-05-17 浏览次数:20671 次
declare @ss varchar(50),@sql varchar(max); set @ss='1,2,3,4'; set @sql='delete from ClassTable where ClassId not in ('+@ss+')'; exec(@sql); --@ss是字符串,你那样写是按一个字符串'1,2,3,4'而不是一个集合
------解决方案--------------------
delete from ClassTable where ClassId not in (+quotename(@NotClassId,'''')+)
delete from StudentTable where ClassId not in (+quotename(@NotClassId,'''')+)
这样试一试
------解决方案--------------------
set @ss='5';
delete from ClassTable where ClassId in (@ss);
这么写呢?