1
SELECT
  dTotalCharge,
  iCarrierInvoiceDetailsID,
  dtPickupDate,
  vcTrackingNum,
  SUM(dTotalCharge) OVER (PARTITION BY iCarrierInvoiceDetailsID
  ORDER BY dtPickupDate, vcTrackingNum
  ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS runningTotal
FROM tblCID

Getting error:

Msg 102, Level 15, State 1, Line 6
Incorrect syntax near 'ROWS'.

Any idea what is wrong with this. I had another problem before PIVOT before. These are examples out of 70-461 Training Kit. I am confused.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
bones
  • 63
  • 2
  • 10
  • Does the query work without the window clause? That is the default window. – Gordon Linoff Jul 08 '15 at 21:10
  • 2
    This ROW-clause is not be used before SQL Server 2012... – Shnugo Jul 08 '15 at 21:29
  • So it is ROW. 2008R2. How would i use windows function in this manner? – bones Jul 09 '15 at 00:08
  • @bones The OVER clause with a ROW or RANGE clause was introduced in SQL Server 2012. Consult the [answers to this question on StackOverflow](https://stackoverflow.com/questions/860966/calculate-a-running-total-in-sqlserver). – TT. Jul 09 '15 at 08:08
  • @bones Obviously, I meant for versions prior to SQL Server 2012, consult the link :) – TT. Jul 09 '15 at 08:36

0 Answers0