* Loop thru sql rows depending on column value

You'd never want to use a loop or cursor for something like this. A tally table or function would be orders of magnitude more efficient.