筛选出查询中的 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)
 ) 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子句中。

相关内容

  • 没有找到相关文章

最新更新