22,302
社区成员




--不用拆分也可以作为条件。
declare @T table (id int,col varchar(1))
insert into @T
select 1,'a' union all
select 2,'b' union all
select 3,'c' union all
select 4,'d'
declare @sql varchar(10)
set @sql='2,4'
select * from @T where charindex(','+ltrim(id)+',',','+@sql+',')>0
/*
id col
----------- ----
2 b
4 d
*/
declare @s varchar(100)
set @s='a,b,c,d'
select * from tb where charindex(','+col+',',','+@s+',')>0