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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Table1 with contents from Table2 1

Status
Not open for further replies.

fdarkness

Programmer
Feb 17, 2006
110
CA
This shouldn't be too difficult but it's not working for me. Hopefully someone can help!

I have two tables:

Table1
Name Number UserID
James Jimmy E1255 <NULL>
Jones Tom E8544 <NULL>
Loeb Lisa E9988 <NULL>

Table2
UserID FirstName LastName
12 Jimmy James
55 Tom Jones
49 Lisa Loeb

I need to updat Table1.UserID with Table2.UserID, matching Table1.Name to Table2.LastName + ' ' + Table2.FirstName.

I'm assuming a nested query, but when I did it, the subquery returned more than 1 value. Any idea how to build this?
 
Code:
Update Table1
Set    UserId = Table2.UserId
From   Table1
       Inner Join Table2
         On Table1.Name = Table2.LastName + ' ' + Table2.FirstName

You should make a backup of your database before continuing. You should also check to make sure there are no duplicates in the table.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Thank you! It worked perfectly!

(And I already have fail-safes set up).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top