Select * from group
where charindex(',b,',','+urserid+',')>0

解决方案 »

  1.   

    select groupid from [group] where charindex (',b,',','+userid+',')>0
    或者
    select groupid from [group] where ','+userid+',' like '%,b,%'
      

  2.   

    like '%b%'charindex('b',col)>0
      

  3.   

    Select * from group
    where ','+urserid+',' like '%,b,%'
      

  4.   

    select groupid from [group] where ','+userid+',' like '%,b,%'
      

  5.   

    照几位的做了,
    提示错误   
    对数据类型而言运算符无效。运算符为 add,类型为 text
    真实的表是这样的
    groupid   |    urserid
      1             2,3,4,
      2             3,5,6,
      3             2,22,8,
      4             22,3,10,
    我想找到所有 urserid 为 2的groupid 
    如何实现啊
      

  6.   

    userid数据类型改为 VARCHAR(8000)应该够用了.
      

  7.   

    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
      

  8.   

    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]