Solved

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

Posted on 2014-01-05
7
1,453 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 17

Accepted Solution

by:
John Gates earned 500 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 34

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 34

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

948 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now