Home Forums SQL Server 2005 T-SQL (SS2K5) How to Build a single row with groups of fields from several rows per key RE: How to Build a single row with groups of fields from several rows per key

  • Avraham de-Haan (10/6/2012)


    i have several rows like:

    Customer sn val1, val2, Val3 ..... (sn is a seq# from 1 to 15)

    A 1 31 54

    A 2 98 21 65

    A 3 44 67 11

    B ...

    I want to get A sinle row:

    Customer val1_1, Val1_2, val1_3, val2_1, val2_2, Val2_3, val3_1, val3_2,.....

    A 31 54 98 21 65 44 67

    B

    The Single row built will be used to update a database table.

    Please an efficient solution.

    Of course, "It Depends", but putting it all on one row is likely not the most efficient solution to begin with. We might be able to come up with something very effecient if you explained what these values actually represent.

    --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)