Solved

Parsing City and State From One Field

Posted on 2011-09-22
5
256 Views
Last Modified: 2012-05-12
I've read all of the post and I don't think this one has been answered.  I have a field that has CITY ST.  I need to break them out into two fields.  No commas just a space between CITY and ST.  I've already done the ST as that was the easy part.  Also, the solution needs to be something I can put into a query.  Thanks for your help.
0
Comment
Question by:DocB1973
  • 3
  • 2
5 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36582734

try this query

select field,left([field],instr([field]," ")-1) as City, mid([field],instr([field]," ")+1) as State
from tableName
0
 

Author Comment

by:DocB1973
ID: 36582785
Thank for the quick reply.  It handles everything except when the city has more than one name.  Exp: Grand Rapids MI.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 36582817

ok try this

select field,left([field],instrrev([field]," ")-1) as City, mid([field],instrrev([field]," ")+1) as State
from tableName




for other fomats you will then need a UDF to do the parsing
0
 

Author Comment

by:DocB1973
ID: 36582941
Fantasic!  Works like a charm.
0
 

Author Closing Comment

by:DocB1973
ID: 36582951
Great job for something you think you know how to do but it turns out it's more difficult than you think.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 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