1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
WITH tblresult AS (SELECT M.Account_ID AS Account
, SUM(T.HoursActual) AS Hr
, SUM(T.PickingLines) AS LINES
, (
SELECT SUM(S.Planned) AS PLN
FROM dbo.Shot AS S
WHERE T.Transaction_ID = S.TransactionID
) AS PlnHr
FROM dbo.tblTrans AS T
INNER JOIN dbo.tblMg AS M
ON T.J_ID = M.J_ID
WHERE T.Activity_Date BETWEEN DATEADD(week, DATEDIFF(week, 0, GETDATE()), 0) -- premier jour de la semaine courante
AND DATEADD(day, -1, DATEADD(week, DATEDIFF(week, 0, GETDATE()) + 1, 0)) -- dernier jour de la semaine courante
AND M.Account_ID = 3
GROUP BY M.Account_ID)
SELECT Account
, sum(Hr) as ActHours
, sum(PlnHr) AS PlanHours
, sum(LINES) AS TotalLines
FROM
tblresult
GROUP BY
Account |
Partager