UNPIVOT in SQL SERVER 2008

CGN007
Posted by CGN007 under Sql Server category on | Points: 40 | Views : 1605
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

Comments or Responses

Login to post response