27,579
社区成员
发帖
与我相关
我的任务
分享
declare @t table (a int,b varchar(20))
insert into @t
select 1,'1,110,20,220,200' union all
select 2,'10,110,2,22' union all
select 2,'10,110,202,20'
declare @i int
set @i=20 --这是参数
select * from @t where charindex(','+ltrim(@i)+',',','+b+',')>0
/*
a b
----------- --------------------
1 1,110,20,220,200
2 10,110,202,20
*/
select *
from tb
where charindex(',1,',','+b+',')>0 --有1的记录
select *
from tb
where charindex(',2,',','+b+',')>0 --有2的记录
select *
from tb
where charindex(',20,',','+b+',')>0 --有20的记录