下图中的亮点显示了我想要实现的逻辑。我意识到语法不正确。
有没有办法有条件地更新 MERGE 语句中的记录,仅当目标表中某一列的值为 NULL,并且源表中相应的值不为 null 时?
你建议如何重写这个?
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
你也许可以使用When Matched And (s.[Created Date] Is Not Null And t.[Created Date] Is Null) Then Update ...
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)