• Well done Magoo; I knew there was a much better way but drew a blank.

    Jeff Moden (9/16/2013)


    Just to backup Maggo's solution... the method he used is called a "CROSSTAB". You could also use a PIVOT although the CROSSTAB solution is usually a touch faster. Such a solution is one of the better ones because it only has to make a pass at the table one time. To wit, it's a common solution for "pivoting" EAV tables of this nature.

    I wish I had read Cross Tabs and Pivots, Part 1 – Converting Rows to Columns[/url] before putting my query together.

    "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