Hi @Sudip Bhatt ,
Please refer below and check whether it is helpful.
drop table if exists Student
Declare @Data xml
set @Data=
'<Root>
<Student>
<Name>Rakesh</Name>
<Marks>80</Marks>
</Student>
<Student>
<Name>Mahesh</Name>
<Marks>90</Marks>
</Student>
<Student>
<Name>Gowtham</Name>
<Marks>60</Marks>
</Student>
</Root>'
create table Student (
Name varchar(10),
Marks int
)
insert into Student values
('Rakesh',90),
('Mahesh',80),
('Jack',80)
DECLARE @archive TABLE
(
ActionType varchar(10),
Name varchar(10),
Marks int
);
Merge into Student as Trg
Using (select d.x.value('Name[1]','varchar(20)') as Name ,
d.x.value('Marks[1]','int') as Marks from
@data.nodes('/Root/Student')as d(x)) as Src
on Trg.Name=Src.Name
When Matched Then update set
Trg.Marks=Src.Marks
when not matched then
insert (Name,Marks) values (Src.Name,Src.Marks)
OUTPUT
$action ,
inserted.*
INTO @archive;
select * from Student
--Name Marks
--Rakesh 80
--Mahesh 90
--Gowtham 60
select * from @archive
WHERE ActionType IN ( 'INSERT', 'UPDATE' );
--ActionType Name Marks
--INSERT Gowtham 60
--UPDATE Rakesh 80
--UPDATE Mahesh 90
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues October--Users always get connection timeout problem when using multi subnet AG via listener. Especially after failover to another subnet