Look up the OUTPUT clause, and the INSERT or MERGE statement. When you add a row to Table B using Merge, you can immediately get back all of the output from the row or rows that were just inserted. Store that output, in a temporary table or table variable, then use it to insert into table A.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills