Skip to content

Instantly share code, notes, and snippets.

@chadsten
Created June 28, 2018 16:20
Show Gist options
  • Save chadsten/f085552354061a1da63ece5499b061d4 to your computer and use it in GitHub Desktop.
Save chadsten/f085552354061a1da63ece5499b061d4 to your computer and use it in GitHub Desktop.
SELECT (SUM(ExtendedCost) /
(SELECT COUNT(*) AS TempCount FROM
(SELECT SnapDate
FROM EpicorReports.dbo.InventorySnapshots AS DayCount
WHERE Datepart(week,DayCount.SnapDate) = Datepart(week,InvSnap.SnapDate) AND Plant <> 'PROJ'
GROUP BY SnapDate)
AS NumOfDays))
AS OnHandValue,
ItemMoveType_c, DATEPART(week, SnapDate) AS Week
FROM EpicorReports.dbo.InventorySnapshots AS InvSnap
WHERE (Plant <> 'PROJ') AND (DATEPART(year, SnapDate) > 2017) AND (DATEPART(week, SnapDate) < DATEPART(week, GETDATE())) AND (BuyToOrder = 'FALSE')
GROUP BY DATEPART(week, SnapDate), ItemMoveType_c
ORDER BY Week
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment