Transpose data

  • Hi,

    The Table is as follows:

    Pk Value

    1 2

    1 Erik

    1 Ringberg

    1 NewYork

    2 3

    2 Dave

    2 Gilliam

    2 Alabama

    I want the below output:

    2 Erik Ringberg New York

    3 Dave Gilliam Alabama

    Here,the column names are dynamic and the number of columns are also dynamic. So,I have generated the PK which will help us to identify the number of record and his values.

    If I get this output I can insert all this values into the table which I have created using column name string..

    Thanks in advance

  • First, it would be a great help if you'd take a little time to post your data in a more readibly usable format so that we can actually write a working example from it. Please read, understand, and follow the methods found in the link in my signature line below.

    Also, you say the number of columns should be dynamic... we can do that but I don't see any data in your example that would require it. Please post more data in the format requested. Thanks.

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