Thread: Query Using Pivot Table
11-30-10, 09:47 #1Registered User
- Join Date
- Nov 2010
Unanswered: Query Using Pivot Table
I am using the below code using PIVOT table.
SELECT * FROM ( SELECT T0.[CardCode], CASE MONTH(T0.[DocDate]) WHEN 1 THEN 'January' WHEN 2 THEN 'February' WHEN 3 THEN 'March' WHEN 4 THEN 'April' WHEN 5 THEN 'May' WHEN 6 THEN 'June' WHEN 7 THEN 'July' WHEN 8 THEN 'August' WHEN 9 THEN 'September' WHEN 10 THEN 'October' WHEN 11 THEN 'November' WHEN 12 THEN 'December' END as [Month], T1.[Price], T1.[Quantity], T2.[BWeight1] FROM ORDR T0 INNER JOIN RDR1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[OITM] T2 ON T1.ItemCode = T2.ItemCode ) As TableDate PIVOT ( SUM(Price*Quantity)/(SUM(BWeight1*Quantity)/1000) FOR [Month] IN ( [January],[February],[March],[April], [May],[June],[July],[August], [September],[October],[November],[December]) ) As PivotTable
What am I doing wrong? Is the syntax wrong?
Thanks & Regards
11-30-10, 13:57 #2Jaded Developer
Provided Answers: 59
- Join Date
- Nov 2004
- out on a limb
haven't got a clue what you are doing wrong, but then again I rarely use SQL server
...presumably you want it moving to the SQL server sectionI'd rather be riding on the Tiger 800 or the Norton