Question : How to update & append at the same time from another table a table in SQL Server

Have a table A

I have a new version with alterations as well as new records called B.

How to update A so any new records/updates from the identically structured table B is added to the rows of A. New information is either new rows or updates to an existing row based on the PK column called Code.

Answer : How to update & append at the same time from another table a table in SQL Server

oops, typo there

the insert should be "left join" not just "left"

insert tableA
select * from tableB t1
left join TableA t2 on t1.code = t2.code
where t2.code is null

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
CREATE PROCEDURE updateinsert
as
BEGIN TRANSACTION
BEGIN TRY

update a
set 	a.fname = b.fname,
	a.lname = b.fname
from tableA a
inner join table b on a.code = b.code

insert tableA
select * from tableB t1
left join TableA t2 on t1.code = t2.code
where t2.code is null
 
 COMMIT
END TRY
BEGIN CATCH
  ROLLBACK
END CATCH
Random Solutions  
 
programming4us programming4us