in  相当于 =SQL-92 标准要求对空值的等于 (=) 或不等于 (<>) 比较取值为 FALSE。当 SET ANSI_NULLS 为 ON 时,即使 column_name 中存在空值,使用 WHERE column_name = NULL 的 SELECT 语句仍返回零行。即使 column_name 中存在非空值,使用 WHERE column_name <> NULL 的 SELECT 语句仍返回零行。当 SET ANSI_NULLS 为 OFF 时,等于 (=) 和不等于 (<>) 比较运算符不遵从 SQL-92 标准。使用 WHERE column_name = NULL 的 SELECT 语句返回 column_name 中含有空值的行。使用 WHERE column_name <> NULL 的 SELECT 语句返回列中含有非空值的行。此外,使用 WHERE column_name <> XYZ_value 的 SELECT 语句返回所有非 XYZ 值和非 NULL的行。

解决方案 »

  1.   

    可以转化一下
    select   count(*)   from   table1   where isnull(col001,'')   not   in   (select   isnull(col001,'')   from   table2)
      

  2.   

    select * from table1 t where not exists(select 1 from table2 where ID=t.ID)--用exists
      

  3.   

    用not in时会出现这种情况,in不会。。
    not in= ..and ..and
    in=..or..or..
    -----null不满足任何=条件的值
      

  4.   

    select count(*) from table1 where col001 not in (select col001 from table2)select count(*) from table1 where col001 is not null and col001 not in (select col001 from table2)
      

  5.   

    SQLSERVE关于IN的帮助中已经说明了NULL对NOT IN的影响.所以在使用NOT IN时,子查询必须排除NULL值.例如:
    select   count(*)   from   table1   where   col001   not   in   (select   col001   from   table2 WHERE col001 IS NOT NULL)
      

  6.   


    select count(*) from table1 where col001 not in (select col001 from table2)select count(*) from table1 where col001 is not null and col001 not in (select col001 from table2)
    --支持
      

  7.   

    select count(*) from table1 where col001 not in (select col001 from table2)select count(*) from table1 where col001 is not null and col001 not in (select col001 from table2)
      

  8.   

    select count(*) from table1 where col001 not in (select col001 from table2)select count(*) from table1 where col001 is not null and col001 not in (select col001 from table2)