title: SQL Update table with cumulative value
body: <p>I have this table:</p>
  
  <pre><code>Date  |StockCode|DaysMovement|OnHand
  29-Jul|SC123    |30          |500
  28-Jul|SC123    |15          |NULL
  27-Jul|SC123    |0           |NULL
  26-Jul|SC123    |4           |NULL
  25-Jul|SC123    |-2          |NULL
  24-Jul|SC123    |0           |NULL
  </code></pre>
  
  <p>The reason only the top row has an OnHand value is because I can get this from another table that stores the current qty on hand for any stock code.</p>
  
  <p>The other records in the table are taken from another table that logs all the movement for any given day.</p>
  
  <p>I want to update the above table so that the OnHand column shows the QtyOnHand for that row's date based on the previous record's stock and movement, such that is looks like this at the end of the update:</p>
  
  <pre><code>Date  |StockCode|DaysMovement|OnHand
  29-Jul|SC123    |30          |500
  28-Jul|SC123    |15          |470
  27-Jul|SC123    |0           |455
  26-Jul|SC123    |4           |455
  25-Jul|SC123    |-2          |451
  24-Jul|SC123    |0           |453
  </code></pre>
  
  <p>I'm currently achieving this with a CURSOR.  But performance really sucks over thousands of records.</p>
  
  <p>Is there some SET-based UPDATE statement I can run that will achieve the same result?</p>