以下子查询返回一些空值和一些值。我想选择非空行,我该怎么做?
,(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'
由于
答案 0 :(得分:3)
使用NULL
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
值未知,因此无法确定相等性。
答案 1 :(得分:2)
将AND LEDGERTABLE.ACCOUNTNAME IS NOT NULL
添加到您的WHERE
子句中。