我应该在这里合并吗?(Should I do merge here?)

编程入门 行业动态 更新时间:2024-10-26 18:18:04
我应该在这里合并吗?(Should I do merge here?)

我有一些不同的项目应该被复制到不同的组织。 我用merge语句完成了这个。 当项目不存在时我工作正常,但下次应该更新它时会在每个组织中创建新项目。

merge items as target using ( select items.name, items.value, items.org from Items ) as source on (target.items.name = source.items.name and target.items.value = '50') when matched then update set target.items.name = source.items.name when not matched by target then Insert(...) Values(...);

我想它有一些东西,条件下次也没有资格,新项目创建,但我不明白为什么..

也许只做简单的插入更好?

I have some some different items that should be copied down to different organizations. I have done this with the merge statement. I works fine one time when items not exists but next time when it should update it creates new items in every organization.

merge items as target using ( select items.name, items.value, items.org from Items ) as source on (target.items.name = source.items.name and target.items.value = '50') when matched then update set target.items.name = source.items.name when not matched by target then Insert(...) Values(...);

I guess it has something todo with that the condition doesn´t qualify next time either and new items creates but I don´t understand why..

Maybe it´s better to just do simple insert?

最满意答案

来自一个组织的项目应更新另一个组织中的项目。

merge语句不支持更新“其他行”。 从概念上讲,它逐行运行。 源和目标已连接(完全外部联接),并且对于每个联接结果,您可以决定发生的一个操作。 对于更新和删除操作发生在连接的目标表行。

您需要使用多个语句。

Items from one organization should update items in another organization.

The merge statement does not support updating "other rows". Conceptually, it operates row-by-row. Source and target are joined (a full outer join) and for each join result you get to decide one action that happens. For update and delete that action happens to the joined target table row.

You need to use multiple statements.

更多推荐

本文发布于:2023-08-03 17:36:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1396397.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在这里   merge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!