I agree with Madhivanan, but just for fun here is the solution that is not mentioned in the article:declare @result table ([month] char(3) primary key, newEmployees int, total int)insert into @resultselect [month], newEmployees, 0from newEmployeesPerMonthdeclare @total intset @total = 0update r set @total = r.total = @total + s.newEmployees from newEmployeesPerMonth s (index=idx_month) inner loop join @reusult r on r.[month]= s.[month] option (force order)select *from @resultorder by [month]
It works if idx_month is clustered index on [month] column.