如果判断一串ID是否在表中
假设表如下
ID text
1 ....
2 ....
4 ....
7 ....
10 ....
.......
n ....
检查id 字符串 "1,2,4" 这个在表中 那么返回 1
如果检查的字符串是 "2,3" ,因为3不在表中那么返回0
[解决办法]
charindex('1,2,4',字段)>0来判断 return 0 else return 1
[解决办法]
create table t1(id int)insert into t1select 1 union allselect 2 union allselect 4go--都在if exists (select 1 from t1 where charindex(','+ltrim(id)+',',','+'1,2,4'+',') = 0)print 0elseprint 1--某个不在if exists (select 1 from t1 where charindex(','+ltrim(id)+',',','+'1,2,3'+',') = 0)print 0elseprint 1drop table t1/*******************10