例: select * from 表名 where charindex(',2,',','+h_add+',')>0
declare @t table(code varchar(10)) insert into @t select '2' insert into @t select '3' insert into @t select '2,3' insert into @t select '3,4'declare @code varchar(10) set @code='2'select * from @t where charindex(','+@code+',',','+code+',')>0
declare @t table(code varchar(10)) insert into @t select '2' insert into @t select '3' insert into @t select '2,3' insert into @t select '3,4'declare @code varchar(10) set @code='2'select * from @t where charindex(','+@code+',',','+code+',')>0/* code ---------- 2 2,3 */
select substring(h_add,1,charindex(',',h_add)+1), substring(h_add,charindex(',',h_add)+1,6) from table
select substring(h_add,1,charindex(',',h_add)+1),case when charindex(',',h_add)=0 then '' else right(h_add,len(h_add)-charindex(',',h_add)) end from table
select * from 表名 where charindex(',2,',','+h_add+',')>0
insert into @t select '2'
insert into @t select '3'
insert into @t select '2,3'
insert into @t select '3,4'declare @code varchar(10)
set @code='2'select * from @t where charindex(','+@code+',',','+code+',')>0
insert into @t select '2'
insert into @t select '3'
insert into @t select '2,3'
insert into @t select '3,4'declare @code varchar(10)
set @code='2'select * from @t where charindex(','+@code+',',','+code+',')>0/*
code
----------
2
2,3
*/
select left('3,4',charindex(',','3,4',len('3,4')-2)-1)
select substring('3,4',charindex(',','3,4')+1,6)
select substring(h_add,1,charindex(',',h_add)+1),case when charindex(',',h_add)=0 then '' else right(h_add,len(h_add)-charindex(',',h_add)) end
from table