Solved

parsing address using tsql

Posted on 2014-01-23
5
326 Views
Last Modified: 2014-02-05
I have a legacy table with input in the address field like this:

CITY OF ACWORTH TAX DEPA -4415 SENATOR RUSSELL
LUCERNE VILLAGE TAX COL -2073 MAIN RD, STE A
BROCKTON CITY (W/S)- COL 45 SCHOOL STREET
YORK COUNTYTREASURER-28 EAST MARKET ST. -
EASTLAND CAD - TAX COLLE P O BOX 914
BLOOMFIELD VILLAGE TREAS P.O. BOX 609
ABBEVILLE CITY - TAX COL P.O. BOX 1170
ABBEVILLE COUNTY - TREAS P O BOX 38
ABBEVILLE CITY - TREASU P O BOX 40

I need to parse out this field to give me only the address. I am hitting a dead end. Help please!
0
Comment
Question by:Leogal
  • 2
  • 2
5 Comments
 

Author Comment

by:Leogal
ID: 39805006
Here is the code I am using at this point. It is not totally doing what I want tho...

   , CASE
              WHEN  [PAddress] > ' ' THEN
                           SUBSTRING( [PAddress],charindex( ' - ', ([PAddress]))  , 25)
                              ELSE ' '
               END AS [addr1]


here are the results , close but not exactly right as I only need the address....

CITY OF ACWORTH TAX DEPA
LUCERNE VILLAGE TAX COL
BROCKTON CITY (W/S)- COL
YORK COUNTYTREASURER-28
 - TAX COLLE P O BOX 914
BLOOMFIELD VILLAGE TREAS
 - TAX COL P.O. BOX 1170
 - TREAS P O BOX 38
 - TREASU P O BOX 40
 - COLLE 269 HIGH ST
 - TAX COLL 60 N PARKE ST
 - TREASURE P O BOX 789
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 39805404
Perhaps something like this:
, CASE 
	WHEN LEN(PAddress) > 0 AND CHARINDEX('-', (PAddress)) > 0 THEN SUBSTRING([PAddress], CHARINDEX('-', (PAddress)) + 1, 25)
	ELSE ' '
  END AS [addr1]

Open in new window

0
 
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 500 total points
ID: 39805406
This is how I tested it:
DECLARE @YourTable TABLE(
		PAddress varchar(100))

INSERT @YourTable(PAddress)
VALUES  ('CITY OF ACWORTH TAX DEPA -4415 SENATOR RUSSELL'),
	('LUCERNE VILLAGE TAX COL -2073 MAIN RD, STE A'),
	('BROCKTON CITY (W/S)- COL 45 SCHOOL STREET'),
	('YORK COUNTYTREASURER-28 EAST MARKET ST. -'),
	('EASTLAND CAD - TAX COLLE P O BOX 914'),
	('BLOOMFIELD VILLAGE TREAS P.O. BOX 609'),
	('ABBEVILLE CITY - TAX COL P.O. BOX 1170'),
	('ABBEVILLE COUNTY - TREAS P O BOX 38'),
	('ABBEVILLE CITY - TREASU P O BOX 40')

SELECT  CASE 
		WHEN LEN(PAddress) > 0 AND CHARINDEX('-', (PAddress)) > 0 THEN SUBSTRING([PAddress], CHARINDEX('-', (PAddress)) + 1, 25)
		ELSE ' '
        END AS [addr1]
FROM    @YourTable

Open in new window

Here is the output:
4415 SENATOR RUSSELL
2073 MAIN RD, STE A
 COL 45 SCHOOL STREET
28 EAST MARKET ST. -
 TAX COLLE P O BOX 914
 
 TAX COL P.O. BOX 1170
 TREAS P O BOX 38
 TREASU P O BOX 40
0
 
LVL 32

Expert Comment

by:awking00
ID: 39806859
>>I have a legacy table with input in the address field like this:
CITY OF ACWORTH TAX DEPA -4415 SENATOR RUSSELL
LUCERNE VILLAGE TAX COL -2073 MAIN RD, STE A
BROCKTON CITY (W/S)- COL 45 SCHOOL STREET
YORK COUNTYTREASURER-28 EAST MARKET ST. -
EASTLAND CAD - TAX COLLE P O BOX 914
BLOOMFIELD VILLAGE TREAS P.O. BOX 609
ABBEVILLE CITY - TAX COL P.O. BOX 1170
ABBEVILLE COUNTY - TREAS P O BOX 38
ABBEVILLE CITY - TREASU P O BOX 40<<
So what do you want to see as the addresses from these?
0
 

Author Comment

by:Leogal
ID: 39837902
I wanted to be able to parse the address field showing only the street address or post office box.
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

947 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

22 Experts available now in Live!

Get 1:1 Help Now