not in 查询无记录问题的解决
在sql server 中使用not in 查询时,常常会出现没有任何结果返回的情况,
如 select * from employee where cname not in (select name from temp_emp where sign='1')
而使用 select * from employee where cname not in('001','002') 却可以查到结果。
产生这种现象的原因是:后面的查询结果中不能有null值,否则就会出现这种错误
所以可以写成
select * from employee where cname not in
(select name from temp_emp where sign='1' and name is not null)
就可以了