这是我的查询
select distinct(Challan_No)
from Challan_tb
where Challan_No not in
(
select Challan_No from Invoice_tb where Customer_ID =2 and InvYear=2013
) and InvYear=2013 and Customer_ID =2
子查询正在返回NULL
,因此外部查询不起作用
请帮忙
如果您不想过多地更改查询的结构,则有一个简单而明显的解决方法:
select distinct(Challan_No)
from Challan_tb
where Challan_No not in
(
select Challan_No from Invoice_tb where Customer_ID =2 and InvYear=2013
and Challan_No is not null --This line is new
) and InvYear=2013 and Customer_ID =2
您可以尝试使用 LEFT JOIN。我认为 Access 会更好地消化这一点。
select distinct(Challan_tb.Challan_No)
from Challan_tb
left join Invoice_tb on Invoice_tb.Challan_No = Challan_tb.Challan_No
where Challan_tb.InvYear=2013 and Challan_tb.Customer_ID=2
and Invoice_tb.InvYear is null --or any other Invoice_tb field