Transform rows into columns

  • Hi 

    I need to transform rows into columns. Besides that everytime there are two or more rows with the same sequence number the values should be placed in the respetive column.

    Please see the attach file

    Thanks

  • littlesun - Thursday, February 9, 2017 6:13 PM

    Hi 

    I need to transform rows into columns. Besides that everytime there are two or more rows with the same sequence number the values should be placed in the respetive column.

    Please see the attach file

    Thanks

    You need either a Pivot or a CROSSTAB and, IMHO, the CROSSTAB is better even though it's an ancient technique.  Please see the following two links.  The first teaches you how to do either and has a proof that the CROSSTAB is usually better and can be made twice as good with a thing called "pre-aggregation" (a term coined by Peter "Peso" Larsson).  The second shows you how to easily build Dynamic CrossTabs.
    http://www.sqlservercentral.com/articles/T-SQL/63681/
    http://www.sqlservercentral.com/articles/Crosstab/65048/

    --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 2 posts - 1 through 1 (of 1 total)

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