• A couple variations (these will get you the same query plan as what rxm posted).

    SELECT isnull(cast(id as varchar(12)),'Total'), sum(cnt)

    FROM @rollup

    GROUP BY id with rollup;

    or...

    -- since we're only grouping on one column

    SELECT isnull(cast(id as varchar(12)),'Total'), sum(cnt)

    FROM @rollup

    GROUP BY id with cube;

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001