The following case, it is simpler to use the data in the cursor looping table #temptable, and then to add the current row and the argument1 in the previous line to the argument2 of the current row.
--drop table #temptable CREATE TABLE #temptable (argument1 int, argument2 int, argument3 datetime) DECLARE @rowc ount int, @argument1 int, @argument2 nvarchar (m), @argument3 datetime set @rowcount =1 set @argument1 =1 set @argument2 =0 set @argument3 =getdate () while (@rowcount <100) begin inserts into #temptable (ARGUMENT1,ARGUMENT2,ARGUMENT3) value S (@argument1, @argument2, @argument3) Set @argument1 = @argument1 + DATEPART (day, @argument3) Set @argument3 = @argument3- 1 Set @rowcount = @rowcount + 1--select * from #temptable declare @lastargument2 int set @lastargument2 =0 SET @
Argument2=0 declare _cursor cursor for (select argument1 from #temptable) open _cursor; FETCH NEXT from _cursor to @argument2 while @ @fetch_status = 0 BEGIN update #temptable set argument2= @argumen t2+ @lastargument2 where CURRENT of the _cursor set @lastargument2 = @argument2 fetch NEXT from _cursor into @argument 2 End Close _cursor deallocate _cursor--select * from #teMptable
Ask a question:
The first fetch next from the _cursor into @argument2 why can't I put it in the first row of the while loop and delete the second line? I remember I was here in error, hehe.