0

is this the "right" way to do that?

merge dbo.tableA as tgt
using (select #temptable.pkid, @spParam1 as col1, @spParam2 as col2 from #temptable)
as src
on tgt.pkid = src.pkid
when not matched by target when
   insert (pkid, thing1, thing2) values (src.pkid, col1, col2)
;

Is there a different or better way?

dotnetN00b
  • 5,021
  • 13
  • 62
  • 95
  • if you hv to insert/update/delete something more then you have to explain that . you should have purpose of using merge like you need output or there are more than one dml. – KumarHarsh Dec 16 '13 at 16:21

1 Answers1

1

without using merge this sql will work for you.

insert into dbo.tableA (pkid, thing1, thing2)
   select #temptable.pkid, @spParam1 as col1, @spParam2 as col2 from #temptable src
   left join dbo.tableA as tgt on tgt.pkid = src.pkid
KumarHarsh
  • 5,046
  • 1
  • 18
  • 22