Solved

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

Posted on 2009-05-16
6
989 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Supress rows in SSRS table based on Like or Soundex 2 39
subtract 1 in Access 2003 query 7 39
Sql Join Problem 2 32
Process mapping 5 27
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now