Help with Update Query

C

Chuck W

Hi,
I have a table called tblLocations that has fields such as LocationID
(autonumber) and UnitID (number). I also have a table called tblMonths1 that
has LocationID (number). I just created a field called UnitID. I want to
run an update query that will match the LocationIDs from the two tables and
then fill in the values for the newly created UnitID field in the tblMonths1
from tblLocations. Can someone help?

Thanks,
 
D

Daryl S

Chuck -

Remember to back up your data before testing any new action queries. This
SQL should work for you (untested):

Update tblMonths1
Set [UnitID] = (Select [UnitID] from tblLocations where
tblLocations.LocationID = tblMonths1.LocationID)
 
K

KARL DEWEY

BACKUP DATABASE BACKUP DATABASE BACKUP DATABASE
There is really no need to duplicate the data UnitID in a second table -
just join tblLocations in each query and you will have it.
After you backup then try this --
UPDATE tblMonths1 INNER JOIN tblLocations ON tblMonths1.LocationID =
tblLocations.[LocationID] SET tblMonths1.UnitID = [LocationID].[UnitID];
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top