Transpose Column in table

  • create table TableA

    ( A int , B int ,c int )

    insert into TableA -- we need to insert only one row

    (1,2,3)

    and i want result like

    TableB

    Col1

    1

    2

    3

  • you need unpivot for this, take a look at the example in this link please.

    http://msdn.microsoft.com/en-us/library/ms177410.aspx

    Just in case if you need the query,

    create table #t

    ( A int , B int ,c int )

    insert into #t Values-- we need to insert only one row

    (1,2,3)

    Select Val FROM

    (Select A,B,C from #t) P

    UNPIVOT (Val FOR val1 in (A,B,C)) unpvt

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

Viewing 2 posts - 1 through 1 (of 1 total)

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