回答

收藏

合并-有条件的匹配后更新。

技术问答 技术问答 288 人阅读 | 0 人回复 | 2023-09-14

下图中的亮点显示了我想要实现的逻辑。我意识到语法不正确。% M! x! I0 z# U3 y. C
只有当目标表中列出的值为空,源表中的对应值不为空时,才能有条件更新MERGE句子中的记录吗?
/ ^$ |0 B# x2 I- P如何建议重写?3 |0 f; Y9 U' T% ?+ X
MERGE dbo.input_311 AS [t]USING dbo.input_311_staging AS <strike>ON ([t].[unique key] = <strike>.[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               
2 I. v+ v; y6 l5 H, u7 P" X    解决方案:                                                               
. x5 R9 Y& s* e( ~                                                                也许可以用When Matched And (s.[Created Date] Is Not Null And t.[Created Date] IsNull) Then Update ...。
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则