Hello,
Can u please send me a link or example of PIVOT table?
I am new in Sql-Server 2005.
Thanks & Regards,
Jitnedra
How to use PIVOT Table in SQL-Server 2005?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Manikavelu VelayuthamRank #413 · 6K reputationPosted Sep 13, 2010, 12:24 AM EDT
GO
SELECT DaysToManufacture, AVG(StandardCost) AS AverageCost
FROM Production.Product
GROUP BY DaysToManufacture;
Result set of above query
DaysToManufacture AverageCost
0 5.0885
1 223.88
2 359.1082
4 949.4105
Pivot Query for above result set
-- Pivot table with one row and five columns
SELECT 'AverageCost' AS Cost_Sorted_By_Production_Days,
[0], [1], [2], [3], [4]
FROM
(SELECT DaysToManufacture, StandardCost
FROM Production.Product) AS SourceTable
PIVOT
(
AVG(StandardCost)
FOR DaysToManufacture IN ([0], [1], [2], [3], [4])
) AS PivotTable;
Pivot Result of above Result Set
Cost_Sorted_By_Production_Days 0 1 2 3 4
AverageCost 5.0885 223.88 359.1082 NULL 949.4105