Row to Column Conversion

  • I am doing a data export and need to do a row to column conversion on one of the tables in my database. The results will then be linked back to the parent tables. I have tried creating a Pivot, but this seems to require some type of calculation be done on one of the columns, which I don't need to do. I just need to transpose the data. Is this right? Or am I missing something? Should I be using a different approach?

    Each group contains anywhere from 1 to 20 records that when completed will look Like:

    ListingID, Photo01, Caption01, Photo02, Caption02. ....... Photo20, Caption20

    A sample of the table is also below.

    A million thanks!

    IDPriorityImage Caption

    50190511230822sm.jpgBathroom

    62190711101004sm.jpgBedroom

    62290811214940sm.jpgBackyard

    62390811214900sm.jpgFront Yard

    62490811214952sm.jpgLiving room

    62500801214952sm.jpgDining Room

    68100801211512sm.jpgScenic View

    69100901020847sm.jpgBathroom

    69200901020908sm.jpgBedroom

    69300901020924sm.jpgBackyard

    69400901020939sm.jpgFront Yard

    69500901021019sm.jpgLiving room

    69600901021038sm.jpgDining Room

    69700901021059sm.jpgFron Entry

    69800901021120sm.jpgBathroom

    69900901021138sm.jpgBedroom

    691000901021156sm.jpgBackyard

  • I would suggest the below,

    If the columns are static, read this[/url]

    Else IF its dynamic read this[/url]

    ELSE (if you are stuck and need help) read this[/url]

    Incidentally all three articles by a most distinguished poster here on SSC 🙂

    If you read the first IF and ELSE I dont think you need to come to the last ELSE

    ---------------------------------------------------------------------------------

  • Thanks for the compliment, Nabha. :blush:

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

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