Skip to content
Advertisement

update and insert into table in with single query

table 1

table 2

Q:> I want this process to be repeat after equal interval of time. if a new value got enter into the table 1 then same value should enter into the table 2 but if existing values enters in table 1 then just update end date of previous same value of table 2 and add one new value with null end date into table 2 (example value H in table 1 and table 2).

we need to use only single query.

with merge we are not able to get this

Advertisement

Answer

if a new value got enter into the table 1 then same value should enter into the table 2 but if existing values enters in table 1 then just update end date of previous same value of table 2 and add one new value with null end date into table 2

Your scenario need a Trigger to be created on Table1. You can put down your logic to update Table2 in the Trigger. See below demo:

Here is Trigger on Table1


–Execution:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement