Monday, January 11, 2010

Grouping Data or Summary Data in SQL Server statement – part 2

In part 1 article we saw some statements that help us in grouping data for summary data or reporting in easiest way.
Let's see GROUPING SET and GROUPING function (introduced in SQL Server 2008):
These are new feature in SQL Server 2008 to allow you with multiple grouping to be returned in one result set (means , here there are two time of groups) .
Let's see this example :




…Last row



So we get the same result set that generated by WITH ROLLUP.
Note: to distinguish the null value that returned by WITH ROLLUP or WITH CUBE or GROUPING SET ,SQL SERVER provides GROUPING function .
This function will return 1 if the row return by the above statements and 0 for other .
So let's see the above example with GROUPING function:

No comments: