我已经编写了一个查询来对税项进行分组,如果税为空,我不想显示税名。这个怎么做?请检查我的 sql server 语句:
SELECT
'CENTRAL EXCISE DUTY' AS 'TaxName',
SUM(TaxAmount) AS 'Tax'
FROM
PMT_InvoiceTaxAttribute
WHERE
InvoiceID = 100
AND TaxAttributeName NOT LIKE '%IBR%'
AND TaxAttributeName NOT LIKE '%CST%'
AND TaxAttributeName NOT LIKE '%VAT%'
UNION
SELECT
'CST' AS 'TaxName',
SUM(TaxAmount) AS 'Tax'
FROM
PMT_InvoiceTaxAttribute
WHERE
InvoiceID = 100
AND TaxAttributeName LIKE '%CST%'
UNION
SELECT
'VAT' AS 'TaxName',
SUM(TaxAmount) AS 'Tax'
FROM
PMT_InvoiceTaxAttribute
WHERE
InvoiceID = 100
AND TaxAttributeName LIKE '%VAT%'
此查询给出的输出如下:
TaxName Tax
------------- -----------
CENTRAL EXCISE DUTY 15000
CST NULL
VAT NULL
在这里,我不想显示 CST 和 VAT,因为它具有空值。