Pivoting Multiple Columns

  • I need to pivot multiple columns. I am better off doing 2 different Pivots and joining them, or using case statements?

    Are there other, better alternatives that I am not aware of?

  • Look for the word multi-aggregate in the following artcle...

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

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thank you Jeff. Any Idea which one would perform better?

  • You should test them side by side to be sure, but in my experience the cross-tab runs just a hair faster on average.

    __________________________________________________

    Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
    Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills

  • Khades (2/11/2011)


    Thank you Jeff. Any Idea which one would perform better?

    I posted that near the end of the article. 😉

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Originally I had just read the multi-aggregate section. But after you said performance was at the end, I decided to read the whole thing and I learned quite a bit :). Thank you.

    Excuse my noobiness with the forums, but how do I get to your other articles (Dynamic Cross-Tabs, EAV/NVP Conversions, pre-aggregation, etc)?

  • Khades (2/14/2011)


    Originally I had just read the multi-aggregate section. But after you said performance was at the end, I decided to read the whole thing and I learned quite a bit :). Thank you.

    Excuse my noobiness with the forums, but how do I get to your other articles (Dynamic Cross-Tabs, EAV/NVP Conversions, pre-aggregation, etc)?

    Just go back to that article and then click on my name at the top of the article.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks!

  • You bet. Thank you for the interest and the feedback.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply