Screenwriters
I have a table as follows:
myTable t1 col2 col3 2 1 3 0 4 0 5 0 6 0
and I want to update every zero on col3 with the col3 value in the previous row plus the col2 value in the current row. So my table will look like this:
myTable t1 col2 col3 2 1 3 4 (1+3) 4 8 (4+4) 5 13 (5+8) 6 19 (6+13)
I miss the logic here, perhaps myopia. I tried using the cursor as follows:
DECLARE @var3 FLOAT DECLARE cursor3 CURSOR FOR SELECT col2, col3 FROM table1 FOR UPDATE OF col3 OPEN cursor3 FETCH FIRST FROM cursor3 WHILE (@@FETCH_STATUS > -1) BEGIN UPDATE @table1 SET col3 = isnull(@var3, 0) + isnull(col2, 0) WHERE CURRENT OF cursor3 FETCH NEXT FROM cursor3 INTO @var3 END
but this is wrong. Any ideas?
Thanks in advance.
sql select sql-server-2005 cursor
Lynx kepler
source share