T-SQL parse street address

Posted on 2009-12-21
Last Modified: 2012-05-08
Need to pull street number and street name separately from an address.  It should be noted that some of these street names may have more than one word in them, i.e.: 123 Oak Lawn Dr.

Question by:Rickzzz
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    please post sample data desired output

    Author Comment

    address='123 Oak Lawn Dr'

    addressName='Oak Lawn Dr.'

    LVL 4

    Accepted Solution

    --assumes the first set of non-space characters are the house numbers

    declare @addr varchar(max)
            ,@firstspace int

    set @addr = '123 Oak Lawn Dr'
    set @firstspace = charindex(' ',@addr)

    select substring(@addr,0,@firstspace)          as addrnum
          ,right(@addr, len(@addr) - @firstspace)  as addrstreet

    --table results
    select substring(addr,0,charindex(' ',addr))          as addrnum
          ,right(addr, len(addr) - charindex(' ',addr))   as addrstreet
    from (select '123 Oak Lawn Dr' as addr) tbl

    Author Closing Comment

    perfect, thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    Title # Comments Views Activity
    Using of  resource governer in sql2014 2 36
    Query - which index being used? 2 25
    sql sproc 2 22
    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    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…

    760 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

    8 Experts available now in Live!

    Get 1:1 Help Now