我的一个字段a里存储的是个象这个的数据 比如 11,22,33 比如 wsl,xx,yy 现在,我就想 判断 他是否 包含一个 字符变量,  我是这样做的
select count(*) from table where a like '%"&b&"%'这样到可以,但范围却扩大了,我只想,让他根据逗号匹配,  因为一旦b=1他也成立,
我只想让他全匹配 11或者22,或者33, 不知道,我说明白没有,不知道sql里有没有这样的方法,

解决方案 »

  1.   

    select count(*) from table where ','+a+',' like '%,"&b&",%'
      

  2.   


    declare @s varchar(100)set @s='11,22,33'select count(*) 
    from 表名 
    where charindex(',' + 字段名 + ',',',' +  @s + ',')>0
      

  3.   

    select count(*) from table where charindex(','+a+',',','+'%"&b&"%'+',')>0
      

  4.   

    谢谢各位了,第一没错,第2个,好象charindex(','+a+',',','+'%"&b&"%'+',')>0 参数反了把,,呵呵,先揭贴