select * from table where content like '%abc%' 
and id 
not in (select * from table where charindex('abc',content)>0)----------------------------------------------------------------这个 SQL 语句本身就不对

解决方案 »

  1.   

    select * from table where content like '%abc%' 
    and id 
    not in (select id from table where charindex('abc',content)>0)
      

  2.   

    select 
        * 
    from 
        table 
    where 
        content like '%abc%' 
        and 
        id not in (select 
                      id 
                   from 
                       table 
                   where 
                       charindex('abc',content)>0)
      

  3.   

    to xueguang(xg):
    谢谢。那为什么得到的结果集不同呢?
    content是ntext字段,有关系吗?
      

  4.   

    什么原因就不知道了,可以看看查出不同结果的content中的数据有什么特别
      

  5.   

    select 
        * 
    from 
        table 
    where 
        content like '%abc%' 
        and 
        id not in (select 
                      id 
                   from 
                       table 
                   where 
                       charindex('abc',content)>=0)
      

  6.   

    数据量大的情况下用like 或用charindex哪个速度会快些啊