• Running totals are best done in reporting environments. SSRS handles this cleanly.

    If you HAVE to get your procedure/T-SQL to do this, look up the article on this site under 'Quirky Update'. There's other information out there also under the nickname 'Serial Update', and a few others. Running Totals in SQL is another set of keywords.

    The Quirky Update article (and ensuing conversations) have some of the tightest, nearly foolproof code to get T-SQL to perform this task... because it's impossible to foolproof it without using a loop otherwise.

    Where is the final destination for this data? If it's a reporting environment, I recommend you let them do the Running Total... just for sanity.


    - Craig Farrell

    Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.

    For better assistance in answering your questions[/url] | Forum Netiquette
    For index/tuning help, follow these directions.[/url] |Tally Tables[/url]

    Twitter: @AnyWayDBA