dbTalk Databases Forums  

parsing address

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss parsing address in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tarig
 
Posts: n/a

Default parsing address - 02-13-2004 , 10:09 AM






Hi this is my first time here, so be patient with me
I'm looking for a way to parse addresses using sql
transact, to store as a DTS.
below are some examples: I would like to separate the
street name and street type in 2 diff. columns.
WILLOW CREEK PL
RED BARN DR
RED BARN DR
CARRINGTON DR
RENNER RD
EDMONTON CT
SPRINGBRANCH DR
HILLROSE DR
CEDAR RIDGE DR
LARTAN TRL
PRESIDENT GEORGE BUSH HWY

Tarig


Reply With Quote
  #2  
Old   
Allan Mitchell
 
Posts: n/a

Default Re: parsing address - 02-13-2004 , 11:04 AM






OK so I am presuming that the PL,DR,CT,HWY is the type and the rest the
name?

What I would do is read the string from right to left and stop at the first
space. This is the TYPE
Now read from left to right for the length of the string - where you found
the space for TYPE and this is the NAME

so imagine @str is your field name

DECLARE @str varchar(50)
SET @str = 'Sunset BLVD'

select
LTRIM(RTRIM(LEFT(@str,len(@str) - CHARINDEX(' ',reverse(@str))))) as
[NAME],
LTRIM(RTRIM(RIGHT(@str,CHARINDEX(' ',reverse(@str))))) as [TYPE]







--

Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org


"Tarig" <anonymous (AT) discussions (DOT) microsoft.com> wrote

Quote:
Hi this is my first time here, so be patient with me
I'm looking for a way to parse addresses using sql
transact, to store as a DTS.
below are some examples: I would like to separate the
street name and street type in 2 diff. columns.
WILLOW CREEK PL
RED BARN DR
RED BARN DR
CARRINGTON DR
RENNER RD
EDMONTON CT
SPRINGBRANCH DR
HILLROSE DR
CEDAR RIDGE DR
LARTAN TRL
PRESIDENT GEORGE BUSH HWY

Tarig




Reply With Quote
Reply




Thread Tools
Display Modes

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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.