• A lot depends on whether the mathematical operations needed can be performed by queries using aggregates, joins the apply operator, and so on. On what you've told us, there's nothing that says it can't be done with a single SQL statement and equally nothing that says it can be done with multiple operations and loops. As a general rule, it's a good idea to try to aoid using explicity loops (and of course explicit cursors) but there are a few cases where the general rule doesn't actually fit (usually where someone has the schema design screwed up, but some real cases too).

    Tom