June 18, 2003 at 12:18 pm
Hello,
I have a field that contains street names, a sample of which could be expressed as follows:
Bailey ST
Barton STREET
Beck RD
Birch WAY
Bonita Road
I need to isolate the suffix of the street names (ST, STREET, RD, WAY, Road) and remove them from the data (I have a 'suffix' field in which I used UPDATE statments to populate the field with a designated street name suffix).
In every case the suffix is at the end of the street name, and is preceeded with a space. The length of the suffix varies.
Is there a way I could use RIGHT with SUBSTRING and LEN to achieve this, or do I need to take another approach?
Thanks!
CSDunn
June 18, 2003 at 12:28 pm
-- St and Rd first
UPDATE MyTable
SET Address = SUBSTRING(AddressField, LEN(RTRIM(AddressField))-3, LEN(RTRIM(AddressField)))
WHERE RIGHT(RTRIM(AddressField, 3)) = ' St'
OR RIGHT(RTRIM(AddressField, 3)) = ' Rd'
I think you could use the same technique for the rest of the fields...
June 18, 2003 at 12:38 pm
June 18, 2003 at 12:44 pm
Just be careful of addresses like "13 Barton Street #200". My solution would leave these types of records unaffected and rely on either a more complex where condition, or manual updates...
June 18, 2003 at 2:27 pm
Thanks, this is very helpful!
CSDunn
June 19, 2003 at 9:37 am
You might also try this:
Select Left(Address,Len(Address) - CharIndex(' ',Reverse(Address)))
June 19, 2003 at 10:21 am
Thanks, this is great!
quote:
Select Left(Address,Len(Address) - CharIndex(' ',Reverse(Address)))
June 19, 2003 at 5:38 pm
I would probably create a table to hold the values you want to replace and then do something like the following...
UPDATE t
SET Addr = SUBSTRING(t.Addr, LEN(t.Addr) - LEN(S.Streetname), LEN(S.Streetname)) + ' ' + S.Streetname
FROM Table t
JOIN Streetnames S ON right(t.Addr,LEN(s.Streetname) = s.Streetname
As stated before you really need to be careful about the replacement as some of the words you would replace may leave you with incorrect data.
Gary Johnson
DBA
Sr. DB Engineer
Edited by - gljjr on 06/19/2003 5:39:28 PM
Gary Johnson
Microsoft Natural Language Group
DBA, Sr. DB Engineer
This posting is provided "AS IS" with no warranties, and confers no rights. The opinions expressed in this post are my own and may not reflect that of my employer.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply