在MSSQL 2008中編寫SQL語句時使用到了not in 遇到了一個陷阱
select top 10 * from A where AID NOT IN (select BPID From B where BID='1' )
在返回的BPID中存在null值的時候,即使AID滿足NOT IN(BPID_Values)也不會返回數據,改成如下語句就可以了
select top 10 * from A where AID NOT IN (select BPID From B where BID='1' and BID not null )