Code Snippet posted by:
CGN007 | Posted on: 6/22/2012 | Category:
SQL Server Codes | Views: 467 | Status:
[Member] |
Points: 40
|
Alert Moderator
Input Table
VendorID Rahul Sourav Sunil
-------------------------------------
1 5 3 9
2 8 4 6
SELECT VendorID,EmployeeName,Orders
FROM tempCTE
UNPIVOT
(Orders FOR EmployeeName IN ([Rahul],[Sourav],[Sunil]) )AS unpvt
Output
VendorID EmployeeName Orders
--------------------------------------
1 Rahul 5
1 Sourav 3
1 Sunil 9
2 Rahul 8
2 Sourav 4
2 Sunil1 6