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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 horizontal to vertical array?

Author  Topic 

David92595
Starting Member

8 Posts

Posted - 2012-11-29 : 20:19:07
Hello,

Not sure if there is any basic info you need to know...I'm running SQL Server 2008 Standard.

I need to create a query that has data from multiple columns (Columns 1-6 with coresponding Date started and Date Completed data) displayed vertically, but also has the column name the preeceeding column to identify it...along with other data (Record number, status).

Record Number, Status, Column Name, Date Started, DateCompleted
1, Open, Column 1, 1/1/2012, 2/1/2012,
2, Hold, Column 2, 1/3/2012, 3/1/2012,
1, Open, Column 3, 2/5/2012, 4/6/2012,
3, Closed, Column 4, 5/10/2012, 7/25/2012,
2, Hold, Column 5, 3/9/2012, 4/1/2012,
1, open, Column 6, 10/10/2012, 12/12/2012,


Please reply with any question you may have. Sorry, I did the best I could to describe what I need, the formating wasn't helping either. I went with CSV, if it helps.

As Always, any help would be greatly apprechated.
Thank you,
David92595

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-11-29 : 21:31:11
Can you explain with expected output?
Go to Top of Page

David92595
Starting Member

8 Posts

Posted - 2012-11-30 : 12:39:56
By Horizontal I mean Column 1 -6 would be normal columns in a table.
I need to take a normal table

Column1,Column2,Column3,Column14,Column5,Column6, Date Started, DateCompleted
Data, Data, Data, Data, Data, Data, Data, Data,
Data, Data, Data, Data, Data, Data, Data, Data,
Data, Data, Data, Data, Data, Data, Data, Data,

With data in each column and turn it into

Column Name,Date Started, Date Completed
Column1,data, data,
Column2,data, data,
Column3,data, data,
Column4,data, data,
Column5,data, data,
Column6,data, data,

Hope this helps explain thing a bit better,
David92595
Go to Top of Page

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2012-11-30 : 14:25:55
Check for UNPIVOT and you can find lots of post for it.
Go to Top of Page
   

- Advertisement -