Can you specify an order unmatched rows are inserted in a SQL Server 2008 MERGE Statement? -


i using merge statement upsert. rows not present in destination, them inserted in order. unfortunately, seems order clause isn't supported merge statement. there way in 1 statement? see example better idea of trying do:

create table #destination (ident int not null identity(1,1), id int not null,   value int not null) insert #destination (id,value) values (1,50)  create table #source (id int not null, value int not null) insert #source (id,value) values (1,100),(3,300),(2,200)  merge #destination d using #source s     on d.id = s.id when matched      update      set d.value = s.value when not matched     insert (id,value)     values (s.id,s.value);  select * #destination order ident /*  see:     1, 1, 100     2, 3, 300     3, 2, 200 want achieve:     1, 1, 100     2, 2, 200     3, 3, 300 */ 

the reason want write unit test code performs merge , want insertions in deterministic order. know there ways around this, if there way order insertion of merge easiest.

so right not possible. documentation on merge, operation of inserts, deletes, , updates unordered; burried in it's explanation of how top affects it:

the top clause further reduces number of joined rows specified value , insert, update, or delete actions applied remaining joined rows in unordered fashion. is, there no order in rows distributed among actions defined in when clauses. example, specifying top (10) affects 10 rows; of these rows, 7 may updated , 3 inserted, or 1 may deleted, 5 updated, , 4 inserted , on.


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -