Skip to content

Instantly share code, notes, and snippets.

@chadsten
Created January 9, 2017 16:42
Show Gist options
  • Save chadsten/2549e50bc34d49340f932d105f368b5b to your computer and use it in GitHub Desktop.
Save chadsten/2549e50bc34d49340f932d105f368b5b to your computer and use it in GitHub Desktop.
SELECT TOP (100) PERCENT PartNum, CONVERT(DECIMAL(16, 4), CEILING(SUM(OurShipQty) * 2)) AS YearTotal, CONVERT(DECIMAL(16, 4), CEILING(SUM(OurShipQty) / 6))
AS MonthAvg, COUNT(PartNum) AS Hits
FROM dbo.v_InvoiceRegisterForTurns
WHERE (InvoiceDate > DATEADD(month, - 6, GETDATE())) AND (Plant = 'DIST') AND (InvoiceTerms NOT IN ('16', '26', '14', 'PORD', '50%D', '50%S')) AND (BuyToOrder = 'false' OR
BuyToOrder IS NULL)
GROUP BY PartNum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment