Introduction
In this article I am going to explain how to use an Over clause with Order By in SQL server 2012. An Over clause is used to determine the partitioning and ordering of a rowset before the associated window function is applied.
The OVER clause in SQL server 2012 works with functions to compute aggregated values such as cumulative aggregates and moving averages.
Here we use an OVER clause to determine the cumulative amount of an invoicetotal. We use an OVER clause with Group By to determine the cumulative amount of an invoicetotal.
Statement that creates a table:
|
createtable mcninvoices |
Statement that inserts data into table:
|
insertinto mcninvoices values (20,'e001',100,100,0.00) |
Statement that shows all the data of mcninvoicetable:

Statement that is used to determine the cumulative amount of an invoicetotal:
|
SELECTinvoiceid,vendorid,invoicetotal, |
Output:


EdPosted Aug 27, 2012, 9:41 AM
The sql query in your output picture doesn't match the output.