Solved

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

Posted on 2009-05-16
6
1,036 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 25

Accepted Solution

by:
lwadwell earned 500 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

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

636 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