SELECT EmployeeID, minutes_worked = SUM(DATEDIFF(MINUTE, '0:00:00', WrkHrs))
FROM dbo.table
-- WHERE ...
GROUP BY EmployeeID;
Du kan formatere det smukt på forsiden. Eller i T-SQL:
;WITH w(e, mw) AS
(
SELECT EmployeeID, SUM(DATEDIFF(MINUTE, '0:00:00', WrkHrs))
FROM dbo.table
-- WHERE ...
GROUP BY EmployeeID
)
SELECT EmployeeID = e,
WrkHrs = RTRIM(mw/60) + ':' + RIGHT('0' + RTRIM(mw%60),2)
FROM w;
Du bruger dog den forkerte datatype. TIME
bruges til at angive et tidspunkt, ikke et interval eller varighed. Ville det ikke give mening at gemme deres arbejdstimer i to adskilte kolonner, StartTime
og EndTime
?