如一个表:
id    用户名串
1     w1,w2,w3
2     w1,w4,w5
3     w2,w3,w4如给一个参数,值是w1,请问怎样列出包含有w1的行,我用:
select id from table1 where w1 in 用户名串但是行不通

解决方案 »

  1.   

    select id, 用户名串 from tb where charindex(',W1,',','+用户名串+',')<>0
      

  2.   

    select id from table1 where 用户名串 like ',w1%' or 用户名串 like '%,w1,%' or 用户名串 like '%w1,'
      

  3.   

    select id, 用户名串 from tb 
    where 'W1' in (''''+replace(用户名串,',',''','''+'''')
      

  4.   

    declare @str varchar(20)
    set @str='W1'
    select * from 表名 where charindex(','+@str+',',','+用户名串+',')>0select * from 表名 where ','+用户名串+',' like '%,'+@str+',%'
      

  5.   

    select id from table1 where charindex(','+@w1+',',','+用户名串+',')>0