Solved

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

Posted on 2009-05-16
6
976 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…

746 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

16 Experts available now in Live!

Get 1:1 Help Now