USE SqlShackMergeDemo GO MERGE TargetProducts AS Target USING SourceProducts AS Source ON Source.ProductID = Target.ProductID -- For Inserts WHENNOT MATCHED BY Target THEN INSERT (ProductID,ProductName, Price) VALUES (Source.ProductID,Source.ProductName, Source.Price) -- For Updates WHEN MATCHED THENUPDATESET Target.ProductName = Source.ProductName, Target.Price = Source.Price;
USING( Select bi.PeopleID, bi.Surname, bi.ForeName,bi.PreferredForeName,bi.PreferredSurname ,import.EmployeeID ,import.EmailAddress From BasicInformation bi InnerJoin ztemp_20220901 as import on bi.PeopleID = import.EmployeeID ) AS Base on Base.PeopleID = PeopleEmailList.PeopleID
When MATCHED THEN Update Set PeopleEmailList.EmailID = Base.EmailAddress;