locked
convert single column to single row RRS feed

  • Question

  • I have a table which contains data as

    Data

    10

    21

    35

    148

    54

    74

    Now i want to convert this single column to single row as:

     

    Data Col1 Col2 Col3 Col4 Col5

    10     21     35   148  54    74

     

    How can i do this in sql server


    markand
    Wednesday, June 15, 2011 2:28 PM

Answers

All replies

  • Will PIVOT SQL query solve your problem?

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

     


    Amey
    Wednesday, June 15, 2011 6:18 PM
  • create table #t (data int)
    insert into #t values (10)
    insert into #t values (20)
    insert into #t values (30)
    select [10] as data,[20] as col1 ,[30] as col2 from #t pivot
    (max(data) FOR data IN ([10], [20], [30]))
     AS p

    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Thursday, June 16, 2011 5:17 AM