Update and Inner Join Question

snoopy92211

New member
Local time
Today, 17:37
Joined
Feb 25, 2005
Messages
7
This is driving me NUTS!! :eek:

I am trying to update a table based on an inner join. Do update tables have to be based on primary keys? arrrh!

the error is saying that my syntax for the update is incorrect. PLEASE HELP!
:(

(ALL and mpslocations are tablenames, respectively)

Code:
db.Execute "Update ALL
INNER JOIN MPSLocations ON ALL.Location_Code=MPSLocations.LocationCode
& "Set ALL.LocationAddress = MPSLocations.StreetAddress, " _
& "Set ALL.LocationCity = MPSLocations.City, " _
& "Set ALL.LocationState = MPSLocations.State, " _
& "Set ALL.LocationZip = MPSLocations.Zip, " _
& "where ALL.Location_Code <> MPSLOCATIONS.LocationCode"
 
You only need a single "Set" and you have an extraneous coma after the last set.

db.Execute "Update ALL
INNER JOIN MPSLocations ON ALL.Location_Code=MPSLocations.LocationCode
& "Set ALL.LocationAddress = MPSLocations.StreetAddress, " _
& "ALL.LocationCity = MPSLocations.City, " _
& "ALL.LocationState = MPSLocations.State, " _
& "ALL.LocationZip = MPSLocations.Zip " _
& "where ALL.Location_Code <> MPSLOCATIONS.LocationCode"

Also your where clause conflicts with the join. The join requires a match between the two tables and the where clause is looking for differences.
 
All -

I made the changes that were suggested.
The statement is x <> y, because I want to update every field where (before the update, the location codes don't match).

However, when I open my 'all' table, the location information from the master table isn't appended to the location fields in table 'all'. What do you suggest?

Thanks!
Angel
 
Last edited:
Use an exists clause... I do a lot of query-checking when i create one to make sure it works... so I'm not sure this syntax is correct... but something like this:

WHERE Exists (select * from ALL,MPSLOCATIONS where ALL.Location_Code=MPSLOCATIONS.LocationCode) = False;

-modest
 
The statement is x <> y, because I want to update every field where (before the update, the location codes don't match).
You are JOINING on the location codes if x <> y, the record will NOT be returned. The query will not update any records - ever!
 

Users who are viewing this thread

Back
Top Bottom