有一个变量@not @not循环累加,成为如下字符串'12525,12524' 然后在语句的 not in(@not) 会出错:在将 varchar 值 '12525,12524' 转换成数据类型 int 时失败。 怎么可以把@not变成sql语句的一部分?使not in (@not) 就是 not in (12525,12524) SQL code: select * from tb where charindex(','+ltrim(ID)+',',''+@idlist+'')=0
where charindex(','+Rtrim(栏位)+',' , ','+@not+',') = 0 用一个动态语句即可。
SQL code:
exec ('select * from tb where id not in(@not)')
SQL code: --or exec('select * from tb where id not in('+@idlist+')')
SQL code:
--用动态SQL或者: select * from 表名 where charindex(','+ltrim(字段名)+',',','+@not+',')>0
纠正 SQL code
Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.Cod