Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Query strip numbers from Street address so only Street shows up

Posted on 2009-05-16
6
Medium Priority
?
1,043 Views
Last Modified: 2012-06-27
I have an Address field in a table.

I need to query the address field and strip the leading digits and the single space after the digits so only the street shows up in the query.

Example BEFORE:
449 Colgate Ave.
16090 Hart Rd.
1625 Woods Ave.

Example AFTER
Colgate Ave.
Hart Rd.
Woods Ave.

Thanks,

Doug
0
Comment
Question by:dougsouders1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 24404459
Hi dougsouders1,

What DBMS are you using?  In Oracle 10.x and above I would consider a REGEXP_REPLACE, in others I may need to do something more complex.

Will it always have leading digits?  If so you may just be able to do a substr(address,instr(address,' ')+1)


lwadwell
0
 

Author Comment

by:dougsouders1
ID: 24404534
Thank you for your response. What I am doing is querying FoxPro tables using a Microsoft FoxPro ODBC driver and serving up web pages using IIS, which pretty much supports all SQL queries. The address1 field always has a customers conventional address, i.e. "1234 Anystreet".

The customer wants to pull all streets in a given city and then see the customers on that street. So on a web page would be all the cities, click on a city and then see all the streets in that city, then click on a street and see all the customers on that street- all pulled from their exising FoxPro program they bought and served up by IIS to a smartphone.

I have only mild SQL and no knowledge of how to write functions. If this is SQL, then where would your snippet above go in a full SQL query with table name customer and field name address1?

I will try your suggestion and let you know if I can figure it out.

Doug
0
 
LVL 41

Expert Comment

by:ralmada
ID: 24404616
select SubStr(addressfield, at(' ', addressfield), len(addressfield)) from yourtable
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 
LVL 25

Accepted Solution

by:
lwadwell earned 2000 total points
ID: 24404617
dougsouders1,

Even with ANSI standards on SQL, not all implementation share the same vision.  SQL is SQL in its simplest form but syntax differences exist - especially when it comes to 'built in' functions.  I have little knowledge of FoxPro myself but with the help of google ... try:

SELECT SUBSTR(address1,AT(' ',address1)+1) as street
FROM customer


lwadwell
0
 
LVL 6

Expert Comment

by:nirojexpert
ID: 24404757
the following statement will remove all ocurrence of 1, 2, 3 from the fieldname.
select
STRTRAN(STRTRAN(STRTRAN('1', address, ''), '2', ''), '3', '') as street from customer
 expand the function till 9 and also for 0
0
 

Author Closing Comment

by:dougsouders1
ID: 31582288
Worked like a charm! PERFECT! Thank you- genius... spent 5 hours on this before your solution.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 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