title: cursor to update a row with values from the previous and current rows
body: <p>Fellow Query Writers,</p>
  
  <p>I have a table as follows:</p>
  
  <pre><code>myTable t1
  col2 col3
   2    1
   3    0
   4    0
   5    0
   6    0
  </code></pre>
  
  <p>and I want to update each zero on col3 with the value of col3 in the previous row plus the value of col2 in the current row. So my table would de like the following:</p>
  
  <pre><code>myTable t1
  col2 col3
   2    1 
   3    4  (1+3)
   4    8  (4+4)
   5    13 (5+8) 
   6    19 (6+13)
  </code></pre>
  
  <p>I'm missing the logic here, short-sightedness perhaps. I was trying it with a cursor as follows:</p>
  
  <pre><code>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 &gt; -1)
  BEGIN
   UPDATE @table1
   SET col3 = isnull(@var3, 0) + isnull(col2, 0)
   WHERE CURRENT OF cursor3
   FETCH NEXT FROM cursor3 INTO @var3
  END
  </code></pre>
  
  <p>but it's wrong.
  Any ideas?</p>
  
  <p>Thanks in advance.</p>