我希望在Merge语句SQL Server中匹配时和不匹配时执行相同的插入操作。
MERGE TargetTable f
USING ( SELECT * FROM SourceTable ) q ON q.PKID = f.PKID
WHEN MATCHED AND ( q.a != f.a OR q.b != f.b OR q.c != f.c ) THEN
INSERT (a,b,c,CreatedDate) VALUES (q.a,q.b,q.c,Getdate());
WHEN NOT MATCHED BY TARGET THEN
INSERT (a,b,c,CreatedDate) VALUES (q.a,q.b,q.c,Getdate());