Separating an address
So I have a table, and in this table is a field "address", which contains address, IE "742 Evergreen Terrace", although some also have a street direction "742 Evergreen Terrace NE".
I need to get these into seperate fields House_Num, Street_Name, Street_Type, and Street_Dir.
Anyone have any tips on how to go about this?
What language are you using for the front end?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Um, it's all being done on MS SQL
You have not specified the version of SQL server you are using. Assuming that you are on SQL server 2005, the following will work.
DECLARE @t TABLE (address VARCHAR(100))
INSERT INTO @t(address) SELECT '742 Evergreen Terrace'
INSERT INTO @t(address) SELECT '742 Evergreen Terrace NE'
x.value('i','VARCHAR(15)') AS House_number,
x.value('i','VARCHAR(15)') AS Street_name,
x.value('i','VARCHAR(15)') AS Street_Type,
x.value('i','VARCHAR(15)') AS Street_dir
CAST('<a><i>' + REPLACE(address, ' ','</i><i>') + '</i></a>' AS XML) AS ad
CROSS APPLY ad.nodes('/a') a(x)
House_number Street_name Street_Type Street_dir
--------------- --------------- --------------- ---------------
742 Evergreen Terrace NULL
742 Evergreen Terrace NE
Jacob Sebastian, SQL Server MVP
By annlinnet in forum .NET
Last Post: 08-11-2008, 07:40 AM
Last Post: 12-13-2006, 02:49 PM
By sailinghunter in forum C++
Last Post: 08-10-2006, 12:44 AM
Last Post: 04-07-2006, 05:21 AM
By kumar_dasari in forum Java
Last Post: 01-30-2006, 01:13 AM
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL