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 |
|
rum23
Yak Posting Veteran
77 Posts |
Posted - 2009-02-06 : 13:27:47
|
| I have a table with the following columns:ProjectID - D_ReclaimPressTest - D_WaterPressTest - D_SewerLineInspan example of the data in this would beB11 - 2002-11-11 00:00:00.000 - 2006-06-11 00:00:00.000 - 2002-05-15 00:00:00.000I am trying to show the results like this in a separate viewProjectID - TestName - TestDateB11 - D_ReclaimPressTest - 2002-11-11 00:00:00.000B11 - D_WaterPressTest - 2006-06-11 00:00:00.000B11 - D_SewerLineInsp - 2002-05-15 00:00:00.000How can I do this? Please help. |
|
|
rum23
Yak Posting Veteran
77 Posts |
Posted - 2009-02-06 : 13:33:27
|
| got it!Select ProjectID, TestName, TestDateFROM (SELECT ProjectID, D_ReclaimPressTest, D_WaterPressTest, D_SewerLineInsp FROM tblProjects)p UNPIVOT (TestDate FOR TestName IN (D_ReclaimPressTest, D_WaterPressTest, D_SewerLineInsp))AS unpvtThanks anyway! |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-06 : 13:43:10
|
| [code]Select ProjectID,'D_ReclaimPressTest' as TestName,D_ReclaimPressTest as TestDatefrom tableunion allSelect ProjectID,'D_WaterPressTest' ,D_WaterPressTest from tableunion allSelect ProjectID,'D_SewerLineInsp' ,D_SewerLineInsp from table[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
|
|
|
|
|