1
Answer

Merge Statement do not use ID

hi
anyone help me 
use master
Go
MERGE INTO dbo.student AS S
USING dbo.Student AS D
ON S.id = D.id
WHEN MATCHED AND (S.name != D.name OR S.Address!= D.Address) THEN
UPDATE SET S.name = D.name,S.Address = D.Address
WHEN NOT MATCHED BY TARGET THEN
INSERT VALUES (D.id, D.name, D.Address)
WHEN NOT MATCHED BY SOURCE THEN
DELETE OUTPUT D.id,$action,inserted.id, deleted.id;
this is my query for merge statement iam  use same table for a source and destination
my requirement is:
please check with name and insert and update do not use id. , please correct the script and send me back
 
Answers (1)
Next Recommended Forum