【发布时间】:2013-02-08 10:38:19
【问题描述】:
我有一个表格和一个数组,我喜欢合并它们。
结构(t=目标,s=源):
ID gID
----------- -----------
13 1
14 1
15 1
16 1
17 2
18 2
19 2
当 t.ID=s.ID 和 t.gID=s.gID 时,什么都不会发生。当 s.ID
我无法在合并查询中构建它:
merge tableT as t
using @array as s
on (t.ID = s.ID) and (t.gID=s.gID)
when not matched and s.ID < 0 then
insert into
when not matched by source then delete;
当每行@array 中的 gID=1 时,查询将删除所有 gID=2。 但只有 gID=1 应该受到影响。
有人知道如何解决这个问题吗?
【问题讨论】:
标签: sql sql-server sql-merge