• Solomon Rutzky (5/5/2010)


    ...the WHILE loop shouldn't be the best performing option, but sadly it is.

    Are you sure Solomon? I would expect the APPLY + $PARTITION approach to be faster (see code posted earlier) as well as being more flexible (it dynamically accounts for extra/fewer partitions) and set-based.