Click here to Skip to main content
15,915,698 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Need to convert single column in to multiple columns.
i.e. 2 column or 3 column.

Please help to do this.

i.e. Select * from TableName gives following output.
1
2
3
4
5
6

but if you convert into two columns it should give following output.
1,2
3,4
5,6

Thanks in Advance.
Posted
Comments
[no name] 22-Apr-11 7:19am    
what you want to do????????
Dave Paras 22-Apr-11 7:56am    
What I want is, pass Comma separated string from front hand to back hand(sql server). back hand will convert Comma separated value in to table. That table will directly used to insert data in other table.
All this things is need for save trip from back hand to front hand and vice a versa.
Sandeep Mewara 22-Apr-11 7:36am    
Not clear.
Dave Paras 22-Apr-11 7:58am    
Need to convert single column in multiple column.
First Select statement return SIX rows each with single column.
But i want output in N Columns. i.e. 2 columns and 3 rows. or 3 columns and 2 rows.

Is it clear?

1 solution

You can use PIVOT for that. Have a look at the link for more info:
http://www.sqldev.org/transactsql/create-multi-column-view-from-single-column-data-101597.shtml[^]

Good luck!
 
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