title: TSQL cumulative column from previous row
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/860966/calculate-a-running-total-in-sqlserver">Calculate a Running Total in SqlServer</a>  </p>
  </blockquote>
  
  
  
  <p>I need to use values from previous row inorder to generate a cumulative value as shown below. Always for each Code for the year 2000 the starting Base is 100.
  I need to ahieve this using tsql code.</p>
  
  <pre><code>id                Code              Yr             Rate           Base        
  
  1                   4               2000           5              100                                  
  2                   4               2001           7              107 (100+7)             
  3                   4               2002           4              111 (107+4)                              
  4                   4               2003           8              119 (111+8)
  5                   4               2004           10             129 (119+10)
  6                   5               2000           2              100
  7                   5               2001           3              103 (100+3)
  8                   5               2002           8              111 (103+8)
  9                   5               2003           5              116 (111+5)
  10                  5               2004           4              120 (116+4) 
  </code></pre>