Solved

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

Posted on 2009-05-16
6
1,019 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
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
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…

679 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