Perform Sum In Update Statement I am trying to run this update statement, but it keeps giving me the error of


  (3 row(s) affected)
  Msg 157, Level 15, State 1, Line 9
  An aggregate may not appear in the set list of an UPDATE statement.


What do I need to do diff in order to be able to have the sum added to the second field?

Create Table #ABCD
(
  time1 decimal(16,4)
  ,time2 decimal(16,4)
)
Insert Into #ABCD(time1) Values
('12.01'), ('13.04'), ('22.22')

Update #ABCD
SET time2 = SUM(time1/60/60)
One way is to calculate the aggregate inside a CTE (I blogged about this last month):

;WITH CTE AS 
(
  SELECT time1, time2, t2 = SUM(time1) OVER()
  FROM #abcd
)
UPDATE CTE SET time2 = t2/60/60;


But I don't understand the value of putting the same SUM(), aggregated over the whole table, into that column for every single row. Seems easier to just store this single value in a variable, or calculate it at runtime (just use the query inside the CTE).