-
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'
SELECT
x.value('i[1]','VARCHAR(15)') AS House_number,
x.value('i[2]','VARCHAR(15)') AS Street_name,
x.value('i[3]','VARCHAR(15)') AS Street_Type,
x.value('i[4]','VARCHAR(15)') AS Street_dir
FROM(
SELECT
CAST('<a><i>' + REPLACE(address, ' ','</i><i>') + '</i></a>' AS XML) AS ad
FROM @t
) t
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
http://blog.beyondrelational.com/
Similar Threads
-
By annlinnet in forum .NET
Replies: 1
Last Post: 08-11-2008, 07:40 AM
-
Replies: 18
Last Post: 12-13-2006, 02:49 PM
-
By sailinghunter in forum C++
Replies: 1
Last Post: 08-10-2006, 12:44 AM
-
Replies: 1
Last Post: 04-07-2006, 05:21 AM
-
By kumar_dasari in forum Java
Replies: 0
Last Post: 01-30-2006, 01:13 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
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
|
Bookmarks