column into a row using select

  • Hi,

    how to make a column into a row using select statement.

    For ex,

    IDCol1Col2

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

    1 A B

    2 D E

    Output Should like this.

    IDCol1

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

    1 A

    1 B

    2 D

    2 E

    Thanks in Advance

  • try the below querry

    select id, col1 from table

    union all

    select id, col2 as 'col1' from table

    order by col1

  • Thanks working fine

  • And for more complex "Columns into Rows/Rows into Columns" Look up the PIVOT and UNPIVOT functions new to 2005. They've proven quite handy.

    ______________________________________________________________________

    Personal Motto: Why push the envelope when you can just open it?

    If you follow the direction given HERE[/url] you'll likely increase the number and quality of responses you get to your question.

    Jason L. Selburg

Viewing 4 posts - 1 through 3 (of 3 total)

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