有一table:fname ids
aa   1,12,23,25,2,41,42
bb   2,32,12
cc   32,1ids字段的值是由几个id组成,且用逗号分开
请问如何筛选出当 ids 含有 2 的行呀??

解决方案 »

  1.   

    select *
    from [table]
    where charindex(',2,',','+ids+',')>0
      

  2.   

    select * from table where charindex('2',ids)>0
      

  3.   

    select * from tb where charindex(',2,',','+ids+',')>0
      

  4.   

    select * from table where charindex(',2,',','+ids+',')>0
      

  5.   

    或者:select * from tb where ','+ids+',' like '%,2,%'
      

  6.   

    哦,myGod,可以结贴了咔咔。。