以下子查询返回一些空值和一些值。 我想选择非空的行,我该怎么做?
,(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'
谢谢
用IS NOT NULL
过滤 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
值是未知的,因此不能确定相等性。
将AND LEDGERTABLE.ACCOUNTNAME IS NOT NULL
添加到WHERE
子句中。