here is in case you run into needing to update a record already there, assuming REF as the primary key:create table #yakperm (ref int, urn bigint)create table #yaktemp (ref int, urn bigint)insert into #yakperm(ref,urn)values (12345, 968574125896),(49492, 293847263465),(15454, 564564654654)insert into #yaktemp(ref,urn)values(15454, 564964694659),(56544, 878596132188),(16546, 548546516541)select * from #yakperm MERGE #yakperm as Target using(select ref,urn from #yaktemp) as source (ref, urn)on (target.ref = source.ref)when matched then update set urn = source.urnwhen not matched then insert (ref,urn) values (source.ref, source.urn);select * from #yakpermdrop table #yakpermdrop table #yaktemp
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx