• Instead of using PIVOT I'd rather go with CrossTab and DynamicCrossTab, since the code structure of PIVOT is kinda weird and it doesn't perform better than the CrossTab methods either.

    I'd recommend to take a look at the CrossTab method referenced in my signature. Once you're familiar how it works you should read the DynamicCrossTab article.

    As a side note: I've seen versions for dynamic Pivot on the web, too. And both will require using dynamic SQL.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]