For example:
merge Master m using Student s on m.ID = s.ID
when not matched then insert (ID, Name, Student) values (s.ID, s.Name, s.Value );
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
HI I have the below query
Insert into Master(ID,NAME,Student)
select ID,Name,Value From Student
here ID is primary column ,
for every iteration i need to check the newly added value from ID column and insert that newly added record into my target table , if no new records are available, it will not insert any records into my target table
how do i implement this logic in sql server
please suggest your inputs here
thank you in advance
For example:
merge Master m using Student s on m.ID = s.ID
when not matched then insert (ID, Name, Student) values (s.ID, s.Name, s.Value );
Hi @Naresh y
If I understand correctly, you can also try this.
;with CTE as(
select ID,Name,Value from Student as A
where not exists(select ID from Master as B where A.ID = B.ID))
insert into Master select ID,Name,Value From CTE;
Best regards,
Percy Tang
If the answer is the right solution, please click "Accept Answer". If you have extra questions about this answer, please click "Comment".
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.