Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

Ahhh I didn't realize I could use Count(*) with OVER() to get a record count without actually grouping the records. This allows me to get rid of both the temp table and variable, thank you :)
–
RachelOct 19 '12 at 17:47

with w as (select usr_id, row_number() over (order by usr_id) as usr_ordinal from usr)
select record_id, ( select usr_id
from w
where usr_ordinal=1+(record_ordinal%(select count(*) from w))
) as usr_id
from ( select record_id, row_number() over (order by record_id) as record_ordinal
from record ) as z;