2014-02-27 85 views
-2

以下子查詢正在返回一些空值和一些值。我想選擇不爲空的行,我會如何做到這一點?在查詢中過濾出空值

 ,(select distinct LEDGERTABLE.ACCOUNTNAME 
    FROM ledgertrans 
    Where Salesline.SalesID = #tempCMs.SALESID and salesline.DIMENSION = 
     (Select top 1 Ledgertrans.Dimension 
     From LedgerTrans 
      Where Ledgertrans.Voucher = #tempCms.InvoiceID and LedgerTrans.AccountNum = Ledgertable.Accountnum) 
) As 'Account' 

由於

回答

3

過濾NULL s的IS NOT NULL

嘗試這種情況:

(select distinct LEDGERTABLE.ACCOUNTNAME 
    FROM ledgertrans 
    Where Salesline.SalesID = #tempCMs.SALESID and salesline.DIMENSION = 
     (Select top 1 Ledgertrans.Dimension 
     From LedgerTrans 
      Where Ledgertrans.Voucher = #tempCms.InvoiceID 
      and LedgerTrans.AccountNum = Ledgertable.Accountnum 
      AND LEDGERTABLE.ACCOUNTNAME IS NOT NULL) 
) As 'Account' 

NULL具有相等測試(!= NULL)濾除,因爲一個NULL值是未知,因此平等不可能是d etermined。

2

AND LEDGERTABLE.ACCOUNTNAME IS NOT NULL添加到您的WHERE條款。