--测试环境 declare @t table(col1 varchar(1),col2 varchar(50)) insert into @t select 'a','0001,0002' union all select 'b','0001,0003' union all select 'c','0001,0002,0004,0003' --查询 select * from @t where charindex(',0003,',','+col2+',')>0 --结果 col1 col2 ---- -------------------------------------------------- b 0001,0003 c 0001,0002,0004,0003(所影响的行数为 2 行)
declare @t table(col1 varchar(1),col2 varchar(50))
insert into @t select 'a','0001,0002'
union all select 'b','0001,0003'
union all select 'c','0001,0002,0004,0003'
--查询
select * from @t where charindex(',0003,',','+col2+',')>0
--结果
col1 col2
---- --------------------------------------------------
b 0001,0003
c 0001,0002,0004,0003(所影响的行数为 2 行)