merge a from b where @a1=@b1
set @a2=@b2, @a3=@a3+@b3
ins (@a4,@a5) values (@b4,@b5);
вместо грамоздкой записи
merge into a using select ... from b on @a1=@b1
when matched then update set @a2=@b2, @a3=@a3+@b3
when not matched then insert (@a4,@a5) values (@b4,@b5);