select * from [table] where charindex(',2,',','+role+',')>0
select * from #a where CharIndex(',2,',role)>0 UNION --在字段中間 如 0,2,3,5 select * from #a where CharIndex('2,',role)=1 UNION --在第一位的 如 2,3 select * from #a where CharIndex(',2',role)>0 and (CharIndex(',2',role)= len(role)-1) --在最後一位的 如 3,2
SELECT [name] FROM t WHERE PATINDEX( '%,2,%' , ','+role+',' )>0name ---------- a e
select * from #a where CharIndex('2,',role)=1 UNION --在第一位的 如 2,3
select * from #a where CharIndex(',2',role)>0 and (CharIndex(',2',role)= len(role)-1) --在最後一位的 如 3,2
----------
a
e