Hi ,
Please can i get some examples and help in understanding the use of MERGE statement please
What is the use of MERGE statement in SQL? How and where all is it used?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Suthish NairRank #92 · 22.8K reputationPosted Nov 6, 2011, 4:45 AM EST
Pravin MoreRank #1,419 · 1.2K reputationPosted Nov 3, 2011, 11:40 PM EDT
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.