Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 HT insert table A record fields into table B

Author  Topic 

keuler
Starting Member

10 Posts

Posted - 2008-06-13 : 18:19:02
All- Supposing I have table_a and table_b. Table_a has fields FIRST_A and LAST_A for people's first and last names. Similarly, table_b has FIRST_B and LAST_B for people's first and last names.

How would I create a record in table_b for each record in table_a, such that for each added record, the values of FIRST_A is copied to FIRST_B and LAST_A is copied to LAST_B. (Table_b will have other fields that are left unfilled.)

Thanks!

-Kurt

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-14 : 00:34:56
UPDATE tb
SET tb.FIRST_B=ta.FIRST_A,
tb.LAST_B=ta.LAST_A
FROM table_a ta
INNER JOIN table_b tb
ON tb.LinkingCol=ta.LinkingCol

linkingcol are columns by which the two tables are related.
Go to Top of Page
   

- Advertisement -