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:
Post a Comment