Reputation: 81
I want to put a condition if [2015]
and [2016]
are NULL then hide row,
but I cant pull it off.
I don't have interest in the billname
if it doesn't have data.
SELECT
IssuedByUserGroup,
BILLNAME,
SUM([2016]) AS [2016],
SUM([2015])AS [2015]
FROM Sum_Orders
PIVOT
(
SUM(Sum_SellPrice)
FOR OrderperiodYear IN ([2016],[2015])
) AS pvt
WHERE ( (MONTH(OrderDate) = MONTH(GETDATE())
AND day(OrderDate) <= DAY(GETDATE())) OR MONTH(OrderDate) < MONTH(GETDATE()))
--This part above is just for getting the data since january 1 to sep 23(to the date)
AND OrderStatus in ('Complete','invoiced')
AND OrderPrefix IN ('LAX6')
GROUP BY BILLNAME,IssuedByUserGroup
ORDER BY IssuedByUserGroup desc
This is returning the following as expected:
Thank you !
Upvotes: 1
Views: 1041
Reputation: 15997
Add COALESCE under GROUP BY
part:
HAVING COALESCE(SUM([2016]), SUM([2015])) IS NOT NULL
Upvotes: 2
Reputation: 382
You should be able to use a WHERE clause below the PIVOT, something like this:
WHERE [2015] IS NOT NULL
Upvotes: 0