title: SUM in SQL Server with PARTITION BY clause
body: <p>I have the following table</p>
  
  <pre><code>QuotationId QuotationDetailId   DriverId    RangeFrom   RangeTo FixedAmount UnitAmount
  -------------------------------------------------------------------------------------------
      10579      7                   1           1          1     1154.00      0.00
      10579      7                   2           2          2     1731.00      0.00
      10579      11                  1           0         10     0.00         88.53
      10579      11                  2           11        24     885.30       100.50
      10579      11                  3           25        34     2292.30      88.53
  </code></pre>
  
  <p>I need to write a query in SQL Server with the following logic, </p>
  
  <ul>
  <li>The grouping is QuotationId + QuotationDetailId. </li>
  <li><p>For each of this block I need to sum from the second line on the value of the previous line for fixed </p>
  
  <pre><code>Amount + UnitAmount * RangeFrom + FixedAmount of the current row
  </code></pre></li>
  </ul>
  
  <p>So in this case the resulting output should be</p>
  
  <pre><code>  QuotationId QuotationDetailId   DriverId    RangeFrom   RangeTo   FixedAmount  UnitAmount
  10579             7                1           1           1        1154.00    0.00
  10579             7                2           2           2        2885.00    0.00
  10579             11               1           0           10       0.00       88.53
  10579             11               2           11          24       1770.60    100.50
  10579             11               3           25          34       7174.90    88.53
  </code></pre>
  
  <p>I've tried several queries but without success, can someone suggest me a way to do that ?</p>
  
  <p>Best regards
  Fabrizio</p>