我有数据表
table
t1   t2               t3
1    name             1 
2    name,name2,name3 2
3    cfm,name         3要怎么样写一个SQL语句才能精确查询出t2列中有 name 的数据
不要用likeselect t1,t2,t3 from table where 'name' in(t2)
这样查询不出来啊,请大家帮忙看看

解决方案 »

  1.   

    不用like, 就用charindex 吧
      

  2.   

    楼主这样的表设计没有更多的选择.从精确性讲, like 与 charindex 都做得到.
    如果要用in的方式, 则只有先把name拆出来. 这个在2000中可以考虑临时表. 在2005中可以考虑表值函数或者xml
    但效率其实并不见得会比 like 或者 charindex 高
      

  3.   

    select t1,t2,t3 from table where charindex('name',t2)>0--orselect t1,t2,t3 from table where t2 like  '%name%'
      

  4.   

    肯定不能用like,如果t2里面有数据为 namesss,name333
    如果用like的话,就不满足我要查询的了,我要精确查询值
      

  5.   

    我先试试select t1,t2,t3 from table where charindex('name',t2)>0
      

  6.   

    select t1,t2,t3 from table where charindex(',name,',','+t2+',')>0--orselect t1,t2,t3 from table where ','+t2+',' like '%,name,%'
      

  7.   

    语句不可用,查询name时,namesss都被查出来了
      

  8.   

    可以了,谢谢sdhylj(青锋-SS(期待Solaris光盘))