Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TSQL rollup -return not null

I am using Rollup clause and you how it shows aggregation at various levels WITH NULL values showing different levels of rollups e.g. rollup(year,month,week) would show subtotals at each level.

I want it rolled up and yet want to see only highest level of aggregation - I don't want to see any null values.

Any idea how can I do that?

Regards, Manjot

like image 782
Manjot Avatar asked Jun 27 '26 01:06

Manjot


1 Answers

What do you mean by "only highest level of aggregation?

You can avoid the NULLs by checking if a column in grouped, like so:

SELECT        CASE WHEN Grouping(GroupID) = 1 THEN '#ALL' ELSE GroupID END AS         GroupID,          
              CASE WHEN Grouping(SubGroupID) = 1 THEN '#ALL' ELSE SubGroupID END AS SubGroupID, 
              Sum(Value)
FROM          Table
GROUP BY      GroupID,
              SubGroupID
WITH ROLLUP

It will display #ALL instead of NULL.

like image 116
Maximilian Mayerl Avatar answered Jun 30 '26 22:06

Maximilian Mayerl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!