Friday, June 3, 2016

Using Grouping function With Rollup in Sql Server

//Rollup Used
SELECT
 CASE WHEN GROUPING(customername) = 1 THEN ‘All Customer’ ELSE customername END CustomerName,
 CASE WHEN GROUPING(itemname) = 1 THEN ‘All Items’ ELSE itemname END ItemName,
 SUM(Quantity*PricePerCase)
FROM orders
GROUP BY customername,itemname
WITH ROLLUP

No comments: