一个表中有两个字段a和b,我需要要查询a字段内容是否包含b字段。急在线等

解决方案 »

  1.   

    简单的包含用charindex就可以了。但是如果相当复杂,那可能要写自定义函数
      

  2.   

    --b在a中
    select * from tb where charindex(b,a)>0
    或select * from tb where a like '%'+b+'%'
      

  3.   

    怎么用这个函数啊,select * from where charindex(a,b)
      

  4.   

    字段a里面有空格,我还需要去除空格,只保留内容部分。其实我是想找出来字段b不包含字段a内容的,请大侠帮忙
      

  5.   


    b中不包含a的?
    那就查a不在b中呗
    select * from tb where charindex(replace(a,' ',''),b)=0

    select * from tb where b like '%'+replace(a,' ','')+'%' 
      

  6.   

    用replace函数是不是更改数据库的内容了?
      

  7.   

    不会更改的。也可以用ltrim 或 rtrim 函数去掉空格