declare @sumQtyBalance decimal(18,2),@sumOrigValueBalance decimal(18,2),@QtyBalance decimal(18,2),@OrigValueBalance decimal(18,2),@rowIndex intset @sumQtyBalance=0set @sumOrigValueBalance=0set @QtyBalance=0set @OrigValueBalance=0declare _cursor cursor for(select QtyBalance,OrigValueBalance,rowIndex from TEMP_0_EAP_Rpt_AM_AMDetailRpt4a34ac88_83cd_456f_ac49_a5c300cd3eca )open _cursor;fetch next from _cursor into @QtyBalance ,@OrigValueBalance,@rowIndex while @@fetch_status = 0begin update TEMP_0_EAP_Rpt_AM_AMDetailRpt4a34ac88_83cd_456f_ac49_a5c300cd3eca set QtyBalance=ISNULL(@QtyBalance,0)+@sumQtyBalance,OrigValueBalance=ISNULL(@OrigValueBalance,0)+@sumOrigValueBalance where rowIndex=@rowIndex set @sumQtyBalance=ISNULL(@QtyBalance,0)+@sumQtyBalance set @sumOrigValueBalance=ISNULL(@OrigValueBalance,0)+@sumOrigValueBalance fetch next from _cursor into @QtyBalance ,@OrigValueBalance,@rowIndex endclose _cursordeallocate _cursor