Last active
September 5, 2017 16:34
-
-
Save chadsten/9ee6c1ae4c04f1aa3ef779df675b5de0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
PartNum, | |
CONVERT(DECIMAL(16, 4), (SUM(OurShipQty) * .5)) AS QuarterTotal, | |
CONVERT(DECIMAL(16, 4), (SUM(OurShipQty) / 3) * .5) AS MonthAvg, | |
CONVERT(DECIMAL(16, 4), (COUNT(PartNum)) * .5) AS Hits, | |
COUNT(DISTINCT CustID) AS Customers, | |
MAX(Plant) AS Plant | |
FROM | |
dbo.v_InvoiceRegisterForTurns | |
WHERE | |
(InvoiceDate > DATEADD(month, - 12, GETDATE())) AND | |
(InvoiceDate <= DATEADD(month, - 9, GETDATE())) AND | |
(InvoiceTerms NOT IN ('16', '26', '14', 'PORD', '50%D', '50%S')) AND | |
(NetExtPrice > 0) AND | |
(BuyToOrder <> 'TRUE') | |
GROUP BY | |
PartNum, | |
Plant |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SELECT
Register.PartNum,
CONVERT(DECIMAL(16, 4), (SUM(OurShipQty) * .5)) AS QuarterTotal,
CONVERT(DECIMAL(16, 4), (SUM(OurShipQty) / 3) * .5) AS MonthAvg,
CONVERT(DECIMAL(16, 4), (COUNT(Register.PartNum)) * .5) AS Hits,
COUNT(DISTINCT CustID) AS Customers, MAX(Plant) AS Plant, AVG(AvgQty) as AvgQty, AVG(StdQty) as StdQty
FROM
EpicorReports.dbo.v_InvoiceRegisterForTurns AS Register Left Join
(SELECT
AVG(OurShipQty) * .5 AS AvgQty, PartNum
FROM
EpicorReports.dbo.v_InvoiceRegisterForTurns AS IR
WHERE
--IR.PartNum = Register.PartNum AND
(InvoiceDate > DATEADD(month, - 12, GETDATE())) AND
(InvoiceDate <= DATEADD(month, - 9, GETDATE())) AND
(InvoiceTerms NOT IN ('16', '26', '14', 'PORD', '50%D', '50%S')) AND
(NetExtPrice > 0) AND
(BuyToOrder <> 'TRUE')
GROUP BY PartNum
) AS AvgQty on Register.PartNum = AvgQty.PartNum Left Join
WHERE
(InvoiceDate > DATEADD(month, - 12, GETDATE())) AND
(InvoiceDate <= DATEADD(month, - 9, GETDATE())) AND
(InvoiceTerms NOT IN ('16', '26', '14', 'PORD', '50%D', '50%S')) AND
(NetExtPrice > 0) AND
(OurShipQty) < (AvgQty + StdQty) AND
(OurShipQty) > (AvgQty - StdQty) AND
(BuyToOrder <> 'TRUE')
GROUP BY
Register.PartNum,
Plant