Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Parsing Variations of a Address String Field

Author  Topic 

george909
Starting Member

4 Posts

Posted - 2011-06-02 : 14:21:28
I need some support with attempting to parse an [Address] field in a SQL table. I need to extract the [House#], [Direction] (if any), [StreetName], and [StreetType].

I was able to extract the [HOUSE#] But seem to be challenged with attempting to do the rest. Below is an example:

[Address]
1234 N BRUSH ST
100 S. MAIN
143121 BUENA VISTA AVE

I am seeking to get the following results.

[HOUSE]
1234
100
143121

[Direction]
N
S.
NULL

[StreetName]
BRUSH
MAIN
BUENA VISTA

[StreetType]
ST
NULL
AVE


For the [House] field I have the following code:
SUBSTRING([ADDRESS],1,(CHARINDEX(' ',[ADDRESS])-1)) AS "HOUSE"

But the rest is challenging due to the direction only certain times in the records.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-06-02 : 14:39:31
There really isn't a good way to do this, there are too many possiblities to consider.For example,
1234 Martin Luther King, Jr. Blvd would be really hard to split out. I know that's helpful to you, but this is why table design should be thought before the data is put in to it!


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -