MS SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMS SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 17th, 2004, 02:00 PM
max.hedroom max.hedroom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 12 max.hedroom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
trimming numbers out of addresses

I'm trying to create a sql statement that returns the whole address field but using a where clause that selects addresses, say, starting with the letter A and ending with the letter D. My problem is that I have numbers in the address field (house numbers) which I'm not sure how to get around in my statement.

Data like this exists in the table: "11185 N. Garden St". The numbers will range between 1 to 5 or so digits long (could probably be longer). So, doing a SUBSTRING won't exactly work unless I can figure out how to take off the number of digits prior to the space seperating the number and the street. There is also be a problem of dealing with addresses like "1183 1/2 N. Garden St." (with 1/2 in the number).

Any ideas on how to start something like this? Anyone want to help me out brainstorming this one?

Reply With Quote
  #2  
Old March 18th, 2004, 10:47 AM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
run this statemet in Query analyser just replace '11185 N. Garden St' by your field name and everything will work fine.
select PATINDEX ( '%[a-z]%' , '11185 N. Garden St' ),LEFT ( '11185 N. Garden St' , PATINDEX ( '%[a-z]%' , '11185 N. Garden St' )-1 ) ,right ('11185 N. Garden St',len('11185 N. Garden St')- PATINDEX ( '%[a-z]%' , '11185 N. Garden St' )+1)

output:
7 ; 11185 ; N. Garden St

explanation:
I looking for the first occurance of any letter (btw, check to see if you server is case Sensitive or not) then I just use left and right

Reply With Quote
  #3  
Old March 19th, 2004, 10:14 PM
max.hedroom max.hedroom is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 12 max.hedroom User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
That's awesome man. Thanks, but do you know how that might translate into mySQL?

Reply With Quote
  #4  
Old March 20th, 2004, 08:34 AM
sypher sypher is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Montreal
Posts: 92 sypher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 10 sec
Reputation Power: 5
not really..I don't know mySQL..but try posting it in the MySql Forum..I'm sure you'll get a quick answer..it's a classic problem.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMS SQL Development > trimming numbers out of addresses


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway