Stairway to T-SQL DML Level 8: Using the ROLLUP, CUBE and GROUPING SET operator in a GROUP BY Clause

  • Greg Larsen

    SSC-Insane

    Points: 20635

    Comments posted to this topic are about the item Stairway to T-SQL DML Level 8: Using the ROLLUP, CUBE and GROUPING SET operator in a GROUP BY Clause

    Gregory A. Larsen, MVP

  • subramanian.rajan

    Valued Member

    Points: 54

    Greg Larsen (1/10/2012)


    Comments posted to this topic are about the item <A HREF="/articles/Stairway+Series/87629/">Stairway to T-SQL DML Level 8: Using the ROLLUP, CUBE and GROUPING SET operator in a GROUP BY Clause</A>

    It is an amazing article on the Rollup, Cube and Grouping SEt operators. Excelling explanation and very good presentation with very simple example.

  • dbuendiab

    SSC Eights!

    Points: 993

    Good article, but I've been surprised with the use of COALESCE() for getting the 'Grand Total' in Listing 3. I think it's better to use the GROUPING() function to know if we are dealing with a subtotal row, and then replace the NULL with the correct label. If you use COALESCE() and there is some NULL value in the column CheckFor, you'll get a mistaken label.

  • BarneyL

    Ten Centuries

    Points: 1044

    Thanks for this, it's a good clear summary of these features.

    Are there any performance gains to be had by switching to use these features over unioning a set of SQL statements together? If so I have a few reports that might benefit from rewriting to use them.

    Barney

  • brichardson 56244

    SSC Rookie

    Points: 48

    Nice article! I had never really thought much about using those powerful options with GROUP BY, but now I will use them more.

    --Bill

  • JGBW12

    SSC Rookie

    Points: 41

    test

  • Robin Sasson

    Hall of Fame

    Points: 3359

    Good article and clear explanation.

    Had do refactor the INSERT statements as my organisation uses SQL 2005.

    :exclamation: "Be brave. Take risks. Nothing can substitute experience." :exclamation:

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply