0

これはそれを行う「正しい」方法ですか?

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)
;

別の方法またはより良い方法はありますか?

4

1 に答える 1

1

マージを使用しなくても、このSQLは機能します。

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
于 2013-12-16T16:23:10.753 に答える