вы можете использовать фильтр
having sum(sales) is not null
редактировать после вашей скрипки
select CustomerName,BillNo, sum(Amount)
from [dbo].[MarginTemp]
where [Type] = 'A'
group by customername,BillNo
после редактирования вашей сегодняшней
SELECT
MAT.BillNo,MAT.ServiceCategoryName,
'Sep-19' AS MonthName,
SUM(case when MAT.ServiceCategoryName = 'Z-Net Revenue'
then MAT.Amount else 0 end) AS Amount
FROM MarginTemp MAT
WHERE
MAT.BillNo='A202019339291'
GROUP BY MAT.BillNo,
MAT.ServiceCategoryName
having SUM(case when MAT.ServiceCategoryName = 'Z-Net Revenue'
then MAT.Amount else 0 end)>0
ORDER BY BillNo ASC;
вы получаете нулевой в вашем запросе, потому чтовы использовали MAT.BillNo,MAT.ServiceCategoryName
в группе, когда только одно имя ServiceCategoryName удовлетворяет условию, а для других оно показывает нулевое значение
после обсуждения, я получил исходную проблему
with cte as
(SELECT MAT.BillNo,
---MAT.ServiceCategoryName,
'Sep-19' AS MonthName
, SUM( case when MAT.ServiceCategoryName='Z-NET Revenue' then MAT.Amount else 0 end) as AMOUNT
, SUM( case when MAT.ServiceCategoryName='Internal Dr Visit Charges' then MAT.Amount else 0 end) as [Internal Dr Visit Charges]
,SUM( case when MAT.ServiceCategoryName='External Dr Visit Charges' then MAT.Amount else 0 end) as [External Dr Visit Charges]
FROM MarginTemp MAT
WHERE MAT.BillNo = 'A202019339291'
GROUP BY MAT.BillNo,
MAT.ServiceCategoryName
) select BillNo,MonthName,max(AMOUNT) as amt,
max([Internal Dr Visit Charges]) as [Internal Dr Visit Charges]
,max([External Dr Visit Charges]) as [External Dr Visit Charges]
from cte
group by BillNo,MonthName