• coolcurrent4u (2/8/2016)


    I get this error

    The CUBE() and ROLLUP() grouping constructs are not allowed in the current compatibility mode. They are only allowed in 100 mode or higher.

    That just means that you're on a 2008+ server, but the compatibility level for the database in which you're executing the query is lower than 100. A compatibility level of at least 100 is required to use ROLLUP().

    You could change the compatibility level of the database in which you're testing it to allow the new syntax.

    Alternatively, the query could be tweaked a bit to work on a lower compatibility level. I just used ROLLUP because it was convenient, since for this problem we want both per-individual sales as well as total sales across all individuals.

    Getting the total sales without a ROLLUP wouldn't require much tweaking.

    If changing the compatibility level of the DB isn't an option, then try your hand at altering my solution (after all, if you're going to be supporting this code, then hopefully you are able to understand it well enough to tweak it :-)).

    If you run into some roadblocks, just let us know.

    Cheers!

    EDIT: I haven't had adequate coffee, so I left out the simplest option: just switch to the WITH ROLLUP syntax from 2005 🙂