Access Custom Query

I have 2 tables. The first contains potential customers with name, address and zip code fields and a SalesId field. The second table contains sales territories with SalesId, BeginningZip and EndingZip fields.

I need a query that will marry the 2 tables together and assign the SalesId value from the sales territories table to the customer's table where the zipcode falls in the beginning and ending zip ranges.  
LVL 3
dwcummingsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeCommented:
After backing up your database, try:

UPDATE table1
SET SalesID = DLOOKUP("SalesID", "Table2", "[BeginningZip] <= '" & table1.ZipCode & "' AND [EndingZip] >= '" & table1.zipcode & "'")
0
Rey Obrero (Capricorn1)Commented:
update customers c, territory t
set c.salesid=dlookup("salesID", "t","[c].[zip] >=  [t].[beginnningZip]  and  [c].[zip] <=[t].[endingzip])
0
yjchong514Commented:
Select * from customerTable a,salesTable b
where a.SalesId=b.SalesId and (a.zipcode>=b.BeginningZip and a.zipcode<=b.EndingZip);

Assumption:
Your current tables:
customerTable
salesTable
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

dwcummingsAuthor Commented:
Thanks for getting back to me so quickly.

Fyed, I tried your suggestion, but it didn't work. It actually deleted values that already existed in the SalesId field.

Capricorn1, I get an error message when I attempted to use your suggestion, that being "Unknown".

Here is my SQL statement. Perhaps I entered something incorrectly.

UPDATE 16263A2 AS C, dbo_tblSalesTerritories AS T SET C.SalesId = DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
0
Rey Obrero (Capricorn1)Commented:

UPDATE [16263A2] AS C, [dbo_tblSalesTerritories] AS T SET C.SalesId = DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
0
dwcummingsAuthor Commented:
Same result - "Unknown" error message.
0
Rey Obrero (Capricorn1)Commented:


UPDATE [16263A2] AS C, [dbo_tblSalesTerritories] AS T SET C.SalesId = " & DLookUp("SalesId","T","[C].[Czip] >= [T].[BeginningZip] and [C].[Czip] <= [T].[EndingZip]");
0
dwcummingsAuthor Commented:
I get a syntax error message.
0
Rey Obrero (Capricorn1)Commented:
try this


UPDATE [16263A2] AS C, dbo_tblSalesTerritories AS T
SET C.SalesID = [T].[SalesId]
WHERE C.Czip>=[T].[BeginningZip] AND C.Czip<=[T].[EndingZip]
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dwcummingsAuthor Commented:
Capricorn1,

It worked like a charm. Thanks for the help.

Doug
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.