Sql 如何合并临时表中的插入列和存储过程中的参数?
这是“正确”的方法吗Sql 如何合并临时表中的插入列和存储过程中的参数?,sql,sql-server,tsql,sql-insert,sql-merge,Sql,Sql Server,Tsql,Sql Insert,Sql Merge,这是“正确”的方法吗 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) ; 是否
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)
;
是否有其他或更好的方法?不使用合并,此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
如果你需要插入/更新/删除更多的内容,那么你必须对此进行解释。您应该有使用合并的目的,就像您需要输出或有多个dml一样。