help w/ pivot query
-
Monday, January 21, 2013 8:23 PM
hi all, i'm trying to pivot the following table but can't seem to get it right. Can someone help?
I have the following columns:
Geo-W | Geo-Y | Geo-R | Port-W | Port-Y | Port-G
0 1 0 0 0 0I would like to pivot so that it look like this:
Geo-W | 0
Geo-Y | 0
...
Port-G | 0
Total | 1Thanks.
All Replies
-
Monday, January 21, 2013 8:25 PMModerator
select [Type], ColValue from myTable UNPIVOT (colValue FOR [Type] IN ([Geo-W],[Geo-Y],[Port-W],[Port-Y],[Port-G])) unpvt
For every expert, there is an equal and opposite expert. - Becker's Law
My blog- Edited by Naomi NMicrosoft Community Contributor, Moderator Monday, January 21, 2013 8:30 PM
- Marked As Answer by Red8Rain Monday, January 21, 2013 8:32 PM
-
Monday, January 21, 2013 8:28 PM
Hi Naomi,
that worked but how do I get the values assocated w/ those columns?
-
Monday, January 21, 2013 8:30 PMModeratorSorry, I got distracted by new e-mails - I updated the query, I meant to post [Type],[ColValue]
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Monday, January 21, 2013 8:32 PM
thank you Naomi. all this time, i was trying to pivot instead of unpivot!

