字段A的值的表示方式为:1,2,3,如何查询出含1的所有记录?如:
 A
1,2,3
2,3
3,4
4,5
5,4
3,4,5如何查询出有4的记录数

解决方案 »

  1.   

    declare @t table([str] varchar(10))
    insert into @t select '1,2,3'
    union all select '2,3'
    union all select '3,4'
    union all select '4,5'
    union all select '5,4'
    union all select '3,4,5'select * from @t where [str] like '%1%'
    select * from @t where [str] like '%4%'
      

  2.   

    select * from TB where charindex(',1,',','+A+',')>0select * from TB where (','+A+',') like '%,1,%'
      

  3.   

    select * from tb where a like '%4,%' or a like '%,4'
      

  4.   

    select * from tb where A like '%4%'
      

  5.   

    select * from tb where A like '%4%'
      

  6.   

    select * from Tablename where A like '%4%'
      

  7.   

    select A from tb where charindex('1',A)<>0
    select count(A) from tb where charindex('4',A)<>0