>> As my knowledge of SQL its limited, is it possible to do this with an SQL query that acts like a kind of loop? <<
No, SQL is declarative and does not like the concept of a loop. We
work with SETS and do them ALL AT ONCE -- no sequential processing. If
you think this weird, loop at LISP and recursion instead of loops.
What we often do is create a table of integers from 1 to (n) and then
JOIN to it for many of things that a procedural language would do in
a loop. We also turn IF-THEN-ELSE logic into CASE expression.
Get a copy of THINKING IN SETS for some help with the mindset
changes. Could be worse; could be LISP
