Link to home
Start Free TrialLog in
Avatar of Ann K
Ann K

asked on

Merge Statement

Is this is correct?
User generated image
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Depends.   What are you trying to accomplish, what is the schema for all these tables, and when you execute it do you receive any kind of error message?  Mind readers we ain't.
try this

MERGE Orders AS O
USING (SELECT order_id FROM NewOrders) AS no
ON (o.order_id = no.order_id)
WHEN MATCHED THEN
    UPDATE SET o.ShippingDate = no.ShippingDate,
                 o.PaymentDate = no.PaymentDate,
                     o.PaymentAmount = no.PaymentAmount
WHEN NOT MATCHED BY TARGET THEN
    INSERT (order_id, CustomerName, ShippingDate,PaymentDate,PaymentAmount)
    VALUES (no.order_id, no.CustomerName, no.ShippingDate,no.PaymentDate,no.PaymentAmount)
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial