This good techinique is preety simple to apply for something that declarative sql does not handle very well.
It always surprises inexperienced developers how this simple and rather common request for a report is actually difficult to handle is pure sql code (no stored procedures or reporting tools like Crystal Reports).
Be aware that if you use it on a large set of data you are likely to blow up your sql server (example customers running totals balances).
I hear that sql 2012 has a new feature that can calculate running totals but haven't tried it yet.
Good post 🙂