Question: Convert this static pivot query to a dynamic pivot query. I am trying to list each product category and the number of units sold by

Convert this static pivot query to a dynamic pivot query. I am trying to list each product category and the number of units sold by month.You should have months as headers across the top and product categories down the side

SELECT * FROM (SELECT pc.Name AS CategoryName, sod.OrderQty, DATENAME(mm,soh.OrderDate) AS ORDERMONTH FROM Production.ProductCategory pc INNER JOIN Production.ProductSubcategory sc ON pc.ProductCategoryID = sc.ProductCategoryID INNER JOIN Production.Product pr ON sc.ProductSubcategoryID = pr.ProductSubcategoryID INNER JOIN sales.SalesOrderDetail sod ON pr.ProductID = sod.ProductID INNER JOIN sales.SalesOrderHeader soh ON sod.SalesOrderID = soh.SalesOrderID) dataTable PIVOT (SUM(OrderQty) FOR ORDERMONTH IN ([January], [February], [March], [April], [May], [June], [July], [August], [September], [October], [November],[December]) )AS PivotTable ORDER BY CategoryName

link to schema: https://i.stack.imgur.com/LMu4W.gif

Convert this static pivot query to a dynamic pivot query. I am

AdventureWorks 2008 OLTP Schema Sales HumanResourccs Person Production Schemas Sales Purchasing Person Production AdventureWorks 2008 OLTP Schema Sales HumanResourccs Person Production Schemas Sales Purchasing Person Production

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!