数据表:table
已知取值 (15,6,17,8)
字段: a 
我要查询 select a from tablewhere a in(15,6,17,8)
这个我会,如果我要反过来怎么查啊 ?比如:
数据表:table
已知取值 15 
字段: a 
要查询Table里a字段包含15的怎么写?不用like,有没好的查询语句

解决方案 »

  1.   

    select * from tb where charindex(',15,' , ',' + a + ',') > 0
      

  2.   


    嗯,这个方式我也试过,可以,有没有办法让 in 倒过来写,也就是select a from tablewhere 15 in(a)这样速度上是不是会好一些,
      

  3.   

    用charindex,或patchindex函数
     
    select a from tablewhere charindex('15',a)>0
    --or
    select a from tablewhere patchindex('%15%',a)>0
      

  4.   

    谢谢各位,先用charindex吧,就是不知道数据量太大会不会影响