Skip to content

Instantly share code, notes, and snippets.

@chadsten
Created September 13, 2018 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadsten/70f76d3f0891b76df54e8a5abf50911a to your computer and use it in GitHub Desktop.
Save chadsten/70f76d3f0891b76df54e8a5abf50911a to your computer and use it in GitHub Desktop.
SELECT EntryPerson, AVG((DATEDIFF(hh, ReceivedDate_c, DateTimeCreated_c) + CASE WHEN Datepart(dw, ReceivedDate_c) = 7 THEN 1 ELSE 0 END) - DATEDIFF(wk,
ReceivedDate_c, DateTimeCreated_c) * 2 - CASE WHEN Datepart(dw, ReceivedDate_c) = 1 THEN 1 ELSE 0 END + - CASE WHEN Datepart(dw, DateTimeCreated_c)
= 1 THEN 1 ELSE 0 END) AS Turnaround, CONVERT(DECIMAL(16, 2), 24) AS HoursInDay
FROM Epicor10.dbo.OrderHed
WHERE (ReceivedDate_c > DATEADD(month, - 3, GETDATE())) AND (ReceivedDate_c <= DateTimeCreated_c) AND (ReceivedDate_c IS NOT NULL) AND
(DateTimeCreated_c IS NOT NULL) AND (EntryPerson IN ('amberl', 'kaitlynn', 'cathys', 'jeffo', 'jamesh', 'keeleighc', 'morganp', 'michelled', 'jenellef', 'elviae', 'faitha',
'ronniel', 'johnh')) AND (DATEDIFF(dd, ReceivedDate_c, DateTimeCreated_c) < 30)
GROUP BY EntryPerson
@blhickman
Copy link

I think this is wrong for calculating hours. Where you have *2, I think it should be *24. The 2 works if you are just counting days, but you need 24, if you are counting hours.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment