Home Forums SQL Server 2008 T-SQL (SS2K8) Rolling Max Value RE: Rolling Max Value<!-- 864 -->

  • Sure. So turning the data set on its side, you could think of the sequence of values like this:

    5,3,2,3,1,4,6....

    The update you described works if you just want to know the highest value at any point along the whole series, but I want to know what the highest value was only for the past (lets say) 3 records. So let's start reading from the left to the right (with the current frame indicated by brackets)

    1) 5],3,2,3,1,4,6. 5 is the highest (by default)

    2) 5,3],2,3,1,4,6. 5 is still the highest

    3) [5,3,2],3,1,4,6. 5 is still the highest

    4) 5,[3,2,3],1,4,6. 3 is now the highest, but you have no way of knowing this since the highest value, against which we were previously comparing to determine the next in the series, is now out of scope.

    If you're aware of a way to use an over clause to partition over a range without the use of ROWS or RANGE, I'd be interested to know.

    Executive Junior Cowboy Developer, Esq.[/url]