set rowcount $last_row select tb.pk, id=identity(10) into #tmp from the_table tb where some condition order by something or other set rowcount 0 select tb.pk, other columns from the_table tb , #tmp t where tb.pk = t.pk and t.id between $first_row and $last_row