Converting column into row

  • Hi,

    I need to convert a single column, result of a query yielding some rows with one column, into single row. I am using SQL 2000. Is it possible to do this with a Query? (Not by procedure)

  • Since we're going short on details -

    are we pivoting or aggregating?

    Before and after sample of what you have and what you'd like would be nifty...Thanks!

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • G'day Mate,

    I think I need to see an example to make this worth your while, but this type of work sounds like it would be covered by a cursor. Hit "Books online" and look for Cursor under "Transact SQL Reference".

    It works by defining a variable data type, and using the process to "fetch" a record and when its done with that, it can "fetch" the next one.

    Using a cursor in conjunction with "Cast" or "Convert" and some of the other text functions I'm guessing you'd be able to stitch something together.

    I hope this might steer you in the right direction. This is where I would start! But for the life of me I can't think how you would be using data this way 🙂

    - DamienB

  • Please see the following article... explains how to do it and how NOT to do it...

    http://www.sqlservercentral.com/articles/Test+Data/61572/

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

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