说我想在SQL中使用MERGE语法比较源表和目标表
当target.close_Date
不等于Source.Close_Date
时,我想更新目标表的End_Dt。
表1
ID Close_Date End_Date
1 NULL 9999-12-31
表2
ID Close_Date
1 2019-01-31
Merge Table1 as Target
Using Table 2 as Source
On (Target.ID = Source.ID_)
WHEN MATCHED and
isnull(Target.Closed_Date,'9999-12-31') = isnull(Source.Closed_Date,'9999-12-31')
THEN
Update Set Table1.End_Dt = cast(getdate() as date));
运行代码后,目标表中没有任何更新。