Skip to content
Advertisement

Update and insert from one table with multiple same ID rows but different column attributes to second table

I would like to update the records from one table to another table and if there are new records then insert those records. In this case, the new records are having the same ID but different column attributes. When I am running the update and insert query, it’s only considering the last entry from table one. It seems that it’s overwriting the data in table 2. How to approach this? I would like to add 2 additional records in table 2 even though the Premise_ID is the same for them.

1st table

Result:

enter image description here

2nd Table

Result:

enter image description here

Advertisement

Answer

You can use a MERGE statement

Remove the two WHERE filters in order to match all Premise_ID rows

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