Pivot Query | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Pivot Query

Can we build a pivot query without Hard coding the column values like in the below case: USE AdventureWorks;
SELECT VendorID, [164] AS Emp1, [198] AS Emp2, [223] AS Emp3, [231] AS Emp4, [233] AS Emp5
(SELECT PurchaseOrderID, EmployeeID, VendorID
FROM Purchasing.PurchaseOrderHeader) p
COUNT (PurchaseOrderID)
FOR EmployeeID IN
( [164], [198], [223], [231], [233] )
) AS pvt
ORDER BY VendorID here i guess the employeeid has been predefined…
can anyone show me to build a query where we can get dynamic columns like cross tab…. Thanking in Advance
Seehttp://www.sqlmag.com/Article/ArticleID/43140/sql_server_43140.html Also refer to chapter 4 of Inside Microsoft® SQL Server 2005: T-SQL Programming
Roji. P. Thomas

Also do google search on Dynamic Cross tab Madhivanan Failing to plan is Planning to fail
Thanks guys…. i tried it with a dynamic sql procedure and it works