title: sql running totals
body: <p>i have a table with a list of items and qty to be sold by a certain due date.
  I am trying to calculate a running total column that would show how many items would have been sold at a certain. below is my attempt to get the running totals but it doesn't work as I expect.</p>
  
  <pre><code>select item, due_date, qty, sum(qty) over (Order by item )
  from apsplan 
  Where item ='19-3102875'
  order by item
  </code></pre>
  
  <p>I get the error:</p>
  
  <blockquote>
    <p>Msg 102, Level 15, State 1, Line 44 Incorrect syntax near 'order'.</p>
  </blockquote>
  
  <p>ps I am using SQL Server 2012.</p>
  
  <p>Here is the alternative suggestion I received from here </p>
  
  <pre><code>SELECT
      item,
      due_date,
      qty,
      (SELECT SUM(t2.qty) FROM apsplan t2 WHERE t2.item &lt;= t1.item and item = '196-31020-005') AS rolling_qty
  FROM apsplan t1
  WHERE
      item = '196-31020-005'
  ORDER BY
      item
  </code></pre>
  
  <p>here is the result - not the running total but the over</p>
  
  <pre><code>item    due_date    qty rolling_qty
  196-31020-005   2017-09-20 00:59:00.000 1.00000000  24.00000000
  196-31020-005   2017-10-06 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2017-11-06 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2017-12-06 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-01-28 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-02-04 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-03-25 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-03-25 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-04-01 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-04-08 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-04-29 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-05-06 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-05-13 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-05-27 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-06-03 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-06-10 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-07-01 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-07-08 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-07-15 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-07-29 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-08-05 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-08-12 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-08-26 01:00:00.000 1.00000000  24.00000000
  196-31020-005   2019-09-02 01:00:00.000 1.00000000  24.00000000
  </code></pre>