合并

编程入门 行业动态 更新时间:2024-10-23 03:18:11
本文介绍了合并-有条件的“何时匹配然后更新"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

下图中的突出显示了我要实现的逻辑.我意识到语法不正确.

The highlights in the image below shows the logic I want to implement. I realize the syntax is incorrect.

是否只有在目标表中其列之一的值为空且源表中的对应值不为空的情况下,才有条件地更新MERGE语句中的记录?

Is there a way to conditionally update a record in a MERGE statement only if it the value of one of its columns in the target table is NULL, and the corresponding value in the source table is not null?

您如何建议重写此内容?

How would you suggest re-writing this?

MERGE dbo.input_311 AS [t] USING dbo.input_311_staging AS [s] ON ([t].[unique key] = [s].[unique key]) WHEN NOT MATCHED BY TARGET THEN INSERT(t.[Created Date]) VALUES(s.[Created Date]) WHEN MATCHED THEN UPDATE SET(t.[Created Date] = s.[Created Date] WHERE s.[Created Date] IS NOT NULL AND t.[Created Date] IS NULL) OUTPUT deleted.*, $action, inserted.*; GO

推荐答案

您可能可以使用当匹配为And(例如[创建日期]不为空且t.[创建日期]为空)时,然后更新... .

更多推荐

合并

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

发布评论

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

>www.elefans.com

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