If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Help with Update Query
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, |
#2
|
|||
|
|||
Help with Update Query
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) -- Daryl S "Chuck W" wrote: 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, |
#3
|
|||
|
|||
Help with Update Query
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]; -- Build a little, test a little. "Chuck W" wrote: 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, |
Thread Tools | |
Display Modes | |
|
|