Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
MariusC
Starting Member
16 Posts |
Posted - 2014-07-07 : 04:56:02
|
Hi guys,I have a table with a lot of data like in the example:unic | nrc | nr_tel | id_stud-----+-----+--------+---------2343 | 123 | 354354 | 1231231 | 432 | 534523 | 324It has 30k rows like this.I want to transpose each row into one column. The output should be like:data -----+2343123 354354 123 1231 432 534523 324How can I do this ?Thanks! |
|
stepson
Aged Yak Warrior
545 Posts |
Posted - 2014-07-07 : 06:02:01
|
[code];with aCTEAS (SELECT 2343 AS unic,123 AS nrc,354354 AS nr_tel,123 AS id_stud UNION ALL SELECT 1231,432,534523,324)SELECT *FROM (SELECT id_stud,[unic],[nrc],[nr_tel] FROM aCTE) p UNPIVOT (fValue FOR colName IN ([unic],[nrc],[nr_tel]))AS unpvt; [/code]output:[code]id_stud fValue colName123 2343 unic123 123 nrc123 354354 nr_tel324 1231 unic324 432 nrc324 534523 nr_tel[/code]Can this help you?sabinWeb MCP |
|
|
MariusC
Starting Member
16 Posts |
Posted - 2014-07-07 : 08:25:35
|
That was not the output I wanted. I solved the problem using this query: select Field from myTable UNPIVOT (Field for ColumnName IN ([unic],[nrc],[nr_tel],[id_stud])) unpvtThanks ! |
|
|
|
|
|
|
|