create table t(groupid int,userid varchar(100)) insert into t select 1,'a,b,c,d' union all select 2,'b,d,e' union all select 3,'a,c' union all select 4,'b,f' select * from t where charindex('b',userid)>0 drop table tgo
create table [group] ( groupid int null, userid varchar(100) ) insert into [group] select 1, 'a,b,c,d,' union all select 2, 'b,d,e,' union all select 3, 'a,c,' union all select 4, 'b,f'select * from [group] where charindex('b', userid)>0drop table [group]
或者
select groupid from [group] where ','+userid+',' like '%,b,%'
where ','+urserid+',' like '%,b,%'
提示错误
对数据类型而言运算符无效。运算符为 add,类型为 text
真实的表是这样的
groupid | urserid
1 2,3,4,
2 3,5,6,
3 2,22,8,
4 22,3,10,
我想找到所有 urserid 为 2的groupid
如何实现啊
insert into t select 1,'a,b,c,d'
union all select 2,'b,d,e'
union all select 3,'a,c'
union all select 4,'b,f'
select * from t where charindex('b',userid)>0
drop table tgo
(
groupid int null,
userid varchar(100)
)
insert into [group]
select 1, 'a,b,c,d,'
union all select 2, 'b,d,e,'
union all select 3, 'a,c,'
union all select 4, 'b,f'select * from [group]
where charindex('b', userid)>0drop table [group]