Hi ,
Please can i get some examples and help in understanding the use of MERGE statement please
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Nov 6, 2011, 9:45 AM
Pravin MorePosted Nov 4, 2011, 3:40 AM
Hi Nethra,
Using Merge , we can Insert/Update records in our database table, without explicitly checking for the existence of records to perform operations like Insert or Update. in single statement
for e.g
MERGE INTO dbo.tbl_Customers AS C
USING dbo.tbl_CustomersTemp AS CT
ON C.CustID = CT.CustID
WHEN MATCHED THEN
UPDATE SET
C.CompanyName = CT.CompanyName,
C.Phone = CT.Phone
WHEN NOT MATCHED THEN
INSERT (CustID, CompanyName, Phone)
VALUES (CT.CustID, CT.CompanyName, CT.Phone)
see here you dont need to check sepratly whether perticular record is alreadty their......you do it in single statment.
Thanks,
Pravin.