Click here to Skip to main content
15,666,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a table which contains data as

Data<br />
10<br />
21<br />
35<br />
148<br />
54<br />

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

Data Col1 Col2 Col3 Col4 Col5<br />
10    21   35   148  54   74

How can i do this in sql server
Updated 21-Jun-11 6:37am
Maciej Los 21-Jun-11 12:48pm    
How many rows is in this single column? In MS SQL Sever 2005 count of columns depends on data type.
See here:

You can use Pivot and Unpivot to change rows into columns and viceversa. This feature is available in SQL 2005+.

Take a look on sql-query-convert-columns-into-rows[^]
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900