• Hugo Kornelis (12/9/2013)


    marcia.j.wilson (12/9/2013)


    Any examples of how these would be used?

    Running totals. Traditionally done with slow set-based code, with a (relatively!) fast cursor, or with some dangerous unsupported side effect of a language feature.

    In SQL Server 2012, very simple:

    SELECT SalesPersonName,

    SaleDate,

    Amount,

    SUM(Amount) OVER (PARTITION BY SalesPersonName

    ORDER BY SaleDate

    ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS RunningTotal

    FROM YourTable

    ORDER BY SalesPersonName, SaleDate;

    Thanks. That helped me get a better picture of why you would use this.