The time data type has a range from 00: 00: 00.0000000 to 23: 59: 59.9999999, so you cannot use the time. You should calculate the hour, minute and second instead.
Something like this might work for you
select H.Val, M.Val, S.Val
from (
select dateadd(second, sum(datediff(second, 0, timeAttendanceHour)), 0) as sumtime
from YourTable
) as T
cross apply (select datedifF(hour, 0, T.sumTime)) as H(Val)
cross apply (select datediff(minute, 0, dateadd(hour, -H.Val, T.sumTime))) as M(Val)
cross apply (select datediff(second, 0, dateadd(hour, -H.Val, dateadd(minute, -M.Val, T.sumTime)))) as S(Val)
If you want to get the result as HH: MM: SS, you can use this:
select cast(H.Val as varchar(10))+':'+right(M.Val+100, 2)+':'+right(S.Val+100, 2)
source
share