SELECT *
FROM
(
SELECT
SalesLineItems.[Item Class Code],
SalesLineItems.[Item Number]
,SalesLineItems.[Customer Name]
,(SELECT CASE ISNULL ([Tax Exempt 1 from Customer Master], '')
WHEN ''
THEN NULL
ELSE CAST ([Tax Exempt 1 from Customer Master] AS DECIMAL (10,2))
END) as [Dispenser Cost]
,SalesLineItems.[GL Posting Date]
,SalesLineItems.[SOP Number]
,CASE WHEN LEFT (SalesLineItems.[SOP Number],2)='CR' THEN sum(SalesLineItems.[Extended Price]*-1) ELSE sum(SalesLineItems.[Extended Price])END as [Extended Price]
,datename(month,SalesLineItems.[GL Posting Date]) as FMonth
,datename(year,SalesLineItems.[GL Posting Date]) as FYear
,CASE WHEN LEFT (SalesLineItems.[SOP Number],2)='CR' THEN sum(SalesLineItems.[QTY]*-1) ELSE sum(SalesLineItems.[QTY])END as [QTY]
FROM
SalesLineItems
WHERE
SalesLineItems.[SOP Type] IN ('Invoice','Return')
AND SalesLineItems.[Void Status] <> 'Voided'
AND SalesLineItems.[Document Status] = N'Posted'
AND SalesLineItems.[Extended Price] != 0
AND SalesLineItems.[Item Class Code] IN (@ItemClassID)
AND datename(year,SalesLineItems.[GL Posting Date]) = @FYear
GROUP BY
SalesLineItems.[Item Class Code]
,SalesLineItems.[Item Number]
,SalesLineItems.[Customer Name]
,SalesLineItems.[Tax Exempt 1 from Customer Master]
,SalesLineItems.[GL Posting Date]
,SalesLineItems.[SOP Number]
) as DerivedTable
PIVOT (sum([Extended Price]) for FMonth in ([January],[February],[March],[April],[May],[June],[July],[August],[September],[October],[November],[December]))
AS NEWMONTH
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
This award recognizes a member of Experts Exchange who has made outstanding contributions to the community within their first year as an expert. The Rookie of the Year is awarded to a new expert who has the highest number of quality contributions.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.