I ran across an article that showed calculating a running total with a twist. In this case, the total is the sum of the previous 5 rows. I decided this could be done more efficiently by converting the code to a more modern, window function approach. This article covers the code change.
Note: this assumes you are on a version of SQL Server that is 2012 or later. For this article, I am writing and testing this code on SQL Server 2019.
The Scenario
As the article shows, we want to totals of the 5 previous rows, based on the