-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerge.sql
More file actions
26 lines (19 loc) · 810 Bytes
/
Merge.sql
File metadata and controls
26 lines (19 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
-- Merge
select * from Employee
select * from [dbo].[UpdatedEmployee_Data]
go
---Just heads up that if there is instead of trigger on the table that you wanna merge,then it is
--possible to do that until you disable trigger from that table
begin tran
Merge Employee as T
using UpdatedEmployee_Data as S
on T.Emp_id = S.Emp_id
when Matched
then update set T.EmpMiddleName = S.EmpMiddleName,
T.Department = S.Department
when Not Matched by Target
then insert ([Emp_id],[EmpFirstName],[EmpMiddleName],[EmpLastName],[EmpGovernmentID],[DateOfBirth],[Department])
values(S.Emp_id,S.EmpFirstName,S.EmpMiddleName,S.EmpLastName,S.EmpGovernmentID,S.DateOfBirth,S.Department)
when Not Matched by source
then delete;
Rollback tran