select * from where 分类 like '%2%'select * from where 分类 like '%2%' or 分类 like '%5%'

解决方案 »

  1.   

    同意楼上的小小:select * from  文章 where 分类 like '%2%'
      

  2.   

    我觉得这样可能好一点
    select * from where CharIndex('2,',分类)>0select * from where CharIndex('2,',分类)>0 Or CharIndex('5,',分类)
      

  3.   

    错了,是这样select * from where CharIndex('2,',分类)>0select * from where CharIndex('2,',分类)>0 Or CharIndex('5,',分类)>0
      

  4.   

    是,我写出来只是给你一个思路,这样还有一个问题,就是
    在使用select * from where CharIndex('2,',分类)>0时,'12,'这样的数据也会被查询出来。再THINKING。
      

  5.   

    declare @a varchar(30),@sql varchar(3000)
    set @a='2,4'
    set @a=replace(@a,',',''' as a union all select ''')
    set @a=''''+@a+''''
    select @a
    exec('select '+@a+' into #tmp')
    select * from 文章 a,#tmp b
    where a.分类=b.a
    go
      

  6.   

    来解决这个Oracle问题。
    http://community.csdn.net/Expert/topic/3890/3890187.xml?temp=.7302973
      

  7.   

    declare @a varchar(30),@sql varchar(3000)
    set @a='2,4'
    set @a=replace(@a,',',''' as a union all select ''')
    set @a=''''+@a+''''
    select @a
    exec('select '+@a+' into #tmp')
    select * from 文章 a,#tmp b
    where a.分类=b.a
    drop table #tmp
    go
      

  8.   

    用这样子
    select * from 文章 where 分类 like '2,%'
    union select * from 文章 where 分类 like '%,2'
    union select * from 文章 where 分类 like '%,2,%'
      

  9.   

    想到了,楼主,可以这样解决。select * from where CharIndex(',2,',','+分类+',')>0select * from where CharIndex(',2,',','+分类+',')>0 Or CharIndex(',5,',','+分类+',')>0
      

  10.   

    to wynbfqny(今无心) ,如果分类为12,2,查询2时,12也会被查出来哦
      

  11.   

    paoluo(一天到晚游泳的鱼) 好主意啊
      

  12.   

    peters() 那样不会查出来,不过还是用paoluo(一天到晚游泳的鱼) 的好
      

  13.   

    我觉得 paoluo(一天到晚游泳的鱼) 的是最好的解决办法,上面chinaandys(降龙十八Key) 的看起来好像太复杂了点 ,谢谢大家的参与和帮助!