The following Error Message is a run time error message introduced in SQL Server 2005.
Msg 158, Level 15, State 1, Line 2
An aggregate may not appear in the OUTPUT clause.
This error message appears when you try to use an aggregate function in the OUTPUT clause of an UPDATE statement. Aggregate functions are not allowed in the OUTPUT clause. For smooth execution remove any used aggregate function from out put clause.