Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何合并临时表中的插入列和存储过程中的参数?_Sql_Sql Server_Tsql_Sql Insert_Sql Merge - Fatal编程技术网

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一样。