Addition to HABO and Rafi is responsible.
For my case, I had to specify the DATEDIFF value for bigint, because my value became too large and caused an arithmetic overflow error.
CAST(DATEADD( ms,AVG(CAST(DATEDIFF( ms, '00:00:00', ISNULL(e.Duration, '00:00:00')) as bigint)), '00:00:00' ) as TIME) as 'avg_time'
Hammafer
source share