Here's the solution for 2000 (it will also work on 2005, but on 2005 you can use the ROW_NUMBER function instead of the subquery that I used in this solution).declare @site_id int, @access_id intselect @site_id = 1, @access_id = 1declare @RefTypeID intselect @RefTypeID = max(referral_type_id) + 1 from referral_type where site_id = @site_id and access_id = @access_idinsert referral_type (site_id,access_id,referral_type_id,referral_type,void,defaultfield)select @site_id, @access_id, (select count(*) + @RefTypeID from referral_upload where referral_type < u.referral_type), referral_type, '', ''from referral_upload uorder by u.referral_type