Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

tsql merge example

MERGE esqlProductTarget T
USING esqlProductSource S
ON (S.ProductID = T.ProductID)
WHEN MATCHED 
     THEN UPDATE
     SET    T.Name = S.Name,
            T.ProductNumber = S.ProductNumber,
            T.Color = S.Color
WHEN NOT MATCHED BY TARGET
THEN INSERT (ProductID, Name, ProductNumber, Color)
     VALUES (S.ProductID, S.Name, S.ProductNumber, S.Color)
WHEN NOT MATCHED BY SOURCE
THEN DELETE;
Source by www.essentialsql.com #
 
PREVIOUS NEXT
Tagged: #tsql #merge
ADD COMMENT
Topic
Name
9+6 =