-- Alter any records needing update update table1 set .... property_id = T2.id .... from table1 T1 join #HOLD H on H.PrimaryKeyColumn=T1.PrimaryKeyColumn join table2 T2 on T2.property = H.property where T1.property_id is null or T1.property_id != T2.id -- Insert new records insert table1 (..., property_id, ...) select ..., T2.id as property_id, ... from #HOLD H where H.PrimaryKeyColumn not in ( select PrimaryKeyColumn from table1 )