表a中有个varchar字段id格式为1,2,3,4....
求个sql语句查找id中包含 4 的数目

解决方案 »

  1.   

    len(id) - replace(id, '4', '') 
      

  2.   

    少写个len,但下面如果出现14,24就不好弄了。不知道mssql里有没有正则替换。
    如果没有,只能是取到.net里处理了。
    len(id) - len(replace(id, '4', ''))
      

  3.   

    包含4?是id为4还是id中含有4?select count(*) from table where id=4
      

  4.   

    select id from table where CHARINDEX('4','id')>0
      

  5.   

    select id from table where id like '%4%'
      

  6.   

    修正
    select id from table where CHARINDEX('4',id)>0
      

  7.   

    避免 14,24 被误查,这样能好些。select id from table where CHARINDEX('4,', id)>0