Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Splitting One field into many- How ?? 2

Status
Not open for further replies.

SeeWard

Programmer
Mar 21, 2005
89
0
0
US
Hello there,
I have a table that was created by pulling in an Excel file. The issue is that there is that City, State, Zip, and County are....in one field. :( How can I break up the string so it is 4 fields respectively?
Thanks
 
SeeWard,

You can parse out the address string using the Mid(), Left() InsStr() and IsNumeric() functions.

EG: If you have a comma after every City Name, you can use

Code:
myCity = Left(myAddressField, inStr(MyAddressField,", ")-1)

The key is to find patterns on which to break out the string into its components. If this for US addresses only, the State should always be 2 characters, the zip should always be numeric...


HTH



John

Use what you have,
Learn what you can,
Create what you need.
 
Thanks John, You gave me the piece of the puzzle I was missing!
Cheers!
 
What if you have City State Zip + 4?

I have some City State Zip and some Zip+4 the format is:
ALLEN PARK MI 48101 (no commas)
and
ALLEN PARK MI 48101-1012 (no commas)
I only want the City (ALLEN PARK) portion how do I do this without counting from the left or right for many Cities in my dbf are different in length and also have space some don't? Thanks

 
Something like this ?
Left(AddressField, InStrRev(RTrim(AddressField)," ")-4)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top