Hi,I've started going around in circles here, but bascially, I have a SProc which generates a temp table with the results:ProductName InStock PurchasedProduct1 746 24Product2 732 NULLProduct3 1000 50Product4 0 17Product5 0 NULLProduct6 0 18
The table is basically built on the fly from the orders table using an agregate function (the InStock value is taken straght from the Stock table) but for a graph I want to make the data: Product1 Product2 etcInStock 746 732Purchased 24 NULL
I've been going through a variaty of example SProcs which make pivot tables but thats not quite what I'm looking for, I just want to turn the data around hehe. Any advise would greatly be apprechiated, if it helps here's the SProc that makes the data (and all its joins) I'm probably going around the houses with this too:create table #StockLevels( CategoryID int, CategoryName nvarchar(50), CurrentStock int, BoughtStock int)--Simply get all the current stock levelsINSERT INTO #StockLevelsSELECT CMRC_Categories.CategoryID, CategoryName, CurrentStock, 0FROM CMRC_Categories LEFT JOIN CMRC_StockLevels ON CMRC_Categories.CategoryID = CMRC_StockLevels.CategoryIDGROUP BY CMRC_Categories.CategoryID, CategoryName, CurrentStock--Update the temp table with only the orders which have been completedUPDATE #StockLevelsSET BoughtStock = ( SELECT SUM(dbo.CMRC_OrderDetails.Quantity * dbo.CMRC_Products.Quantity) AS BoughtStock FROM dbo.CMRC_Orders INNER JOIN dbo.CMRC_OrderDetails ON dbo.CMRC_Orders.OrderID = dbo.CMRC_OrderDetails.OrderID RIGHT OUTER JOIN dbo.CMRC_Products ON dbo.CMRC_OrderDetails.ProductID = dbo.CMRC_Products.ProductID WHERE (dbo.CMRC_Orders.CompletedDate IS NULL) AND (CMRC_Products.CategoryID = #StockLevels.CategoryID) GROUP BY dbo.CMRC_Products.CategoryID HAVING SUM(dbo.CMRC_OrderDetails.Quantity * dbo.CMRC_Products.Quantity) >0)SELECT CategoryName, CurrentStock, BoughtStock FROM #StockLevelsDrop table #StockLevels
ThanksTim