Reputation:
I'm trying to insert into a table column data from another table column in SQL.
For example:
TABLE A: ID, COD_LOC, IMP_TOT
TABLE B: ID, SUP, IMP_TOT
In table B I've the column IMP_TOT filled with NULL. I want to insert the data from tableA.IMP_TOT to tableB.IMP_TOT where A.ID=B.ID.
How can I do that in SQL?
thank you for time
Upvotes: 0
Views: 79
Reputation: 6329
Try something like this:
UPDATE tableB SET IMP_TOT = ( SELECT IMP_TOT FROM tableA WHERE ID = tableB.ID )
MERGE INTO tableB USING tableA ON tabelA.ID = tableB.ID
WHEN MATCHED THEN UPDATE SET IMP_TOT = tableA.IMP_TOT
Upvotes: 1