Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add data from columns C and D in Table 2 to colums A and B in Table 1

Status
Not open for further replies.

cocopud

Technical User
Jan 8, 2002
139
US
We have 2 tables and want to copy/update the data from 2 columns in one table to the other table. One table has 4 columns (f_ident, f_type, s_ident and s_type). The information in columns s_ident and s_type needs to be added to the other table (over 45,000 rows). The other table also has s_ident and s_type columns that are currently empty. The criteria is that Table 1.f_ident = Table 2.f_ident and Table 1.f_type = Table 2._f_type then update the row with the new information.

Any suggestion on the best way to do this? I tried to do an Import Data, so I could create a dts package (will need to do this on another server as well); however, I can't figure out the exact sql statement to do this. Thanks.

 
A basic update statement is all that is needed.
Code:
update table2
   set table2.s_ident = table1.s_ident,
      table2.s_type = table1.s_type
from table1
where Table 1.f_ident = Table 2.f_ident 
   and Table 1.f_type = Table 2._f_type

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top