Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operand data type time is invalid for avg operator...?

Tags:

sql

sql-server

How can I avg(time(4)) in the following query:

  select top 10 avg(e.Duration) from TimeTable e

I'm getting the following error:

Operand data type time is invalid for avg operator.

Duration is type time(4) such as:

Duration
-------------
00:00:10.0000
like image 703
genxgeek Avatar asked Aug 03 '12 00:08

genxgeek


1 Answers

You can use DateDiff( ms, '00:00:00', e.Duration ) to convert the time into an integer number of milliseconds. Use that for your aggregate, then convert the result back, e.g. Cast( DateAdd( ms, 1234, '00:00:00' ) as Time ).

like image 138
HABO Avatar answered Jan 29 '23 19:01

HABO