select row_num identity(5), col1, col2, col3, ... into #tmp from the_table where some_condition select row_num, col1, col2, col3, ... from #tmp order by row