• The problem with these sorts of calculations is that a row of data in a database is completely independant. It does not know or care about its neighbours and so trying to force a calculation like this is going to force the database engine into a realm it doesn't much care for.

    Best solution is to work out the running total in the application that takes the data, be it reporting services, excel or whatever.

    Failing that then this is one of those cases where, from a database perspective, a cursor will be the best solution.

    There are other solutions which avoid cursor use, however they have their own draw backs and are not always very efficient.

    Try running both the set based and cursor solutions with your own data and see which you prefer

    (TIP: when using the cursor solution make sure you filter the select statement that forms the cursor declaration, not the select on the temp table used to create the output)