Posted on 2005-04-08
How come sql server says this is aggregate ? ExceptionTime is using sum()
Please kindly help me rewrite the query to work
Server: Msg 130, Level 15, State 1, Procedure SP_temp_shift_sys_nosched, Line 17
Cannot perform an aggregate function on an expression containing an aggregate or a subquery.
Server: Msg 156, Level 15, State 1, Procedure SP_temp_shift_sys_nosched, Line 21
Incorrect syntax near the keyword 'GROUP'.
SELECT operatorid AS operatorid,sum(round(datediff(n,min(timein),max(timeout))/60.00,2)) as ExceptionTime
WHERE timein Between @shiftdate and (@shiftdate + cast('23:59:59' as datetime))
and timeout Between @shiftdate and (@shiftdate + cast('23:59:59' as datetime))
and excuse <> ' '
and operatorid in ( select distinct operatorid from #tempNoSchedinout)
GROUP BY operatorid
table called inout