表TA内容如下:
Name Class
Tom  1,2,3
Jerry 1,5,6,7
Joan 8,9,10
Jim 11,12,13
求第一个语句,能做到:只列出列表中有1的Name,有10,11等的不能列出
求第二个语句,能做到:只列出列表中有11的Name

解决方案 »

  1.   

    select name from ta where charindex(',1,',','+class+',')>0select name from ta where charindex(',11,',','+class+',')>0
      

  2.   

    select * from [Table]
    where ','+Class+',' like '%,1,%'
      

  3.   

    没有问题,不过我觉得第一还要补充,由于楼主说有1不能有10,11
    select name from ta where charindex(',1,',','+class+',')>0 and charindex(',10,',','+class+',') = 0 and charindex(',11,',','+class+',') = 0