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!

Update using data from another table 1

Status
Not open for further replies.

cumap

IS-IT--Management
Jul 9, 2007
268
US
hello all,

I'm trying to update a StateName field in table 1 using value in abbrStateName from table 2 where that StateName field match with the fullStateName field in the table 2... Here is my code:

Code:
UPDATE Carthead SET Carthead.locState = (SELECT Locations.locState FROM Locations WHERE Locations.locName = Carthead.locState)

I got an error saying: Operation must use updateable query

Can someone tell me where did I'd gone wrong with the query on the above? Thanks!
 
What database are you using.

For Microsoft SQL Server, this should work.

Code:
UPDATE Carthead 
SET    Carthead.locState = Locations.locState
From   Carthead
       Inner Join Locations
         On Carthead.locState = Locations.locName

I'm reasonably certain that this will NOT work with Access, but something similar would.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I'm sorry, this is actually Access db. Would you recommend a way for this?
 
For Access, I think this will work. (It's been a long time since I've done any Access stuff). You should make sure you have a good backup of the database before you try this.

Code:
Update Carthead
       Inner Join Locations
         On Carthead.locState = Locations.locName
SET    Carthead.locState = Locations.locState

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thanks George, you code works flawlessly as usual. Good day!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top