Click here to Skip to main content
14,669,324 members
Rate this:
Please Sign up or sign in to vote.
I have a table which contains data as

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


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
Posted
Updated 21-Jun-11 6:37am
v2
Comments
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: http://social.msdn.microsoft.com/Forums/en-IE/transactsql/thread/a0193a4a-7221-42da-ae5e-5c9047f51912

Rate this:
Please Sign up or sign in to vote.

Solution 1

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[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100