• This is a classic cross-tab or pivot query.

    The hardcoded way:

    http://www.sqlservercentral.com/articles/T-SQL/63681/[/url]

    The dynamic way:

    http://www.sqlservercentral.com/articles/Crosstab/65048/[/url]