Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Merge Sample Code
create table MyOrders( orderid INT NOT NULL PRIMARY KEY, custid INT NOT NULL, empid INT NOT NULL, orderdate DATE NOT NULL ) DECLARE @Orders AS TABLE( orderid INT NOT NULL PRIMARY KEY, custid INT NOT NULL, empid INT NOT NULL, orderdate DATE NOT NULL ); INSERT INTO @Orders(orderid, custid, empid, orderdate) VALUES (2, 1, 3, '20120612'), (3, 2, 2, '20120612'), (4, 3, 5, '20120612'); merge into MyOrders as Tgt using @Orders as Src on Tgt.orderid=src.orderid when matched and (Tgt.custid <> Src.custid or Tgt.empid <> Src.empid or Src.orderdate <> Tgt.orderdate) then update set Tgt.custid = Src.custid, Tgt.empid = Src.empid ,Tgt.orderdate=Src.orderdate when not matched then insert values(Src.orderid,Src.custid, Src.empid ,Src.orderdate) when not matched by source then delete; select * from MyOrders
run
|
edit
|
history
|
help
0
SQl_QUEST_2_PRESENTATION_IMG_COUNT
ankit
SqlServer1282018
student
Import CSV File Into SQL Server Using Bulk Insert
n sei o nome (30.10)
Mala Studentska sve
Manish SQL
test1
Combined Where and having