?
Solved

Writing a query to link to just the first 5 digits of a zip code

Posted on 2014-01-05
7
Medium Priority
?
1,893 Views
Last Modified: 2014-01-20
I have a list of contacts with zip codes that are both 5 digit and 5 digit + 4.  

For example:  12345 and 12345-5555

This is shown in the attached file under the table "Master".

I have another table called "Zip Info" which ties in certain information based on zip code, such as Color and Area, however, this uses zips that are 5 digits only.

How would I write query so that the Zip code is truncated to the first 5 digits so that it can match up to the proper record in the "Zip Info" table.

A sample of the final desired version is shown in the table "FINAL SAMPLE".
Database1.accdb
0
Comment
Question by:daisypetals313
7 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39758201
Give this a try:

SELECT Master.*, [Zip Info].*
FROM Master INNER JOIN [Zip Info] ON Left(Master.Zip, 5)  = Left([Zip Info].Zip,5)

Open in new window

0
 
LVL 18

Accepted Solution

by:
John Gates, CISSP earned 2000 total points
ID: 39758202
You can query with the left statement LEFT(<field name>, 5)
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39758241
Here's one other way.  This allows you to still see the query in Design View.
SELECT Master.ID, Contact, Master.Zip, Color, Area
FROM Master, [Zip Info]
WHERE Left([Master].[Zip],5)=Left([Zip Info].[Zip],5)

Open in new window

Ron
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 40

Expert Comment

by:PatHartman
ID: 39759528
@IrogSinta,
For Jet/ACE unspecified joins result in Cartesian Products which are not updateable.
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 39759963
@PatHartman,
I just tried using Inner Join and once you add the LEFT function, the query is not updateable either so I guess in this instance it doesn't matter.

Ron
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 39760184
I guess that makes sense.
0
 

Author Closing Comment

by:daisypetals313
ID: 39795151
This one worked and was quick setup
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question