本文介绍了合并-有条件的“何时匹配然后更新"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下图中的突出显示了我要实现的逻辑.我意识到语法不正确.
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.[创建日期]为空)时,然后更新... .
更多推荐
合并
发布评论