Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

stripping data from a Varchar feild in Crystal 2008

Posted on 2012-12-26
6
Medium Priority
?
263 Views
Last Modified: 2012-12-27
Good Morning Experts,

I have a field in a SQL 2005 database that is "Address Line 1" which contains street number, street name and in some cases unit numbers as well (sometimes proceeded by a comma, someties not. I need  to export this data as two or if unit number exists then three seperate feilds, "Street Number" "Street Name" and "Unit Number" and I need to remove the comma if one exists as this will be sent as a comma delimeted file in the end.  In addition the numeric portion of the address for example "123 anystreet" sometimes will contains a dash, for example "12-24 anystreet".  I need to maintain the dash character in it's existing location.  Any ideas?

To give an example of the variations I've seen in the data I've got:
"123 anystreet"
"123 anystreet, Unit 1"
"123 anystreet Unit 1"

"123-45 anystreet"
"123-45 anystreet, Unit 1"
"123-45 anystreet Unit1"
"123-45 anystreet Unit 1c"
"123-45 anystreet unit 1-3c & 2-6b"
0
Comment
Question by:ISBTECH
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:rmail
ID: 38721239
You could break the string on the first space and the word 'unit':
http://stackoverflow.com/questions/697519/split-function-equivalent-in-tsql
0
 
LVL 8

Expert Comment

by:hpdvs2
ID: 38721268
There is no clean way to do this, because some people may use "Apt", "Suite", etc... or skip a prefix altogether and give an address like this:

3326 Adler Lane B  
instead of
3326 Adler Lane, Apt B
or
3326 Adler Lane Ste B

If you only had a few things to worry about, like Apt or Unit, I would say go for writing your own code to sort it, but there are so many variations that could exist that it would be tough, with a strong chance of errors that won't be caught with addresses that will get mangled.

So, 2 things

1) Reconsider.  What value is there to having these records separated.  Is there something your company does that will strongly benefit from doing this uncommon practice?  I've had times that I considered it, but it never served any real value.  There is a phrase for garbled data like this, "Garbage In, Garbage Out."  But, I'll leave the business decisions to you/your company.

2) Use Google API's.  Their Canonical Address API lets you enter any address, and it will return if it knows this address, and the correct way to review it, including things like converting "ln" to "lane" or ", 3C" to ", Unit 3C"  
 - Then you can take the data and insert it as you see fit.  Since the address format will be stable, you can depend on your parsing code to operate well.
 - I believe the free version is limited to about 1000 addresses a day, but you can use that to prove your app works, and then pay a small fee to open it up for a bulk transmission to convert everything.  
 - Also, you can flag anything Google didn't recognize, which usually is low, and deal with those ones manually, Often its a typo converting "Lane" to "Street" for instance, but the house number only exists on Lane.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 38721274
Try this formula

WhilePrintingRecords;
Global StringVar Array AddressParts;
Global StringVar StreetNumber;
Global StringVar StreetName;
Global StringVar UnitNumber;
Local NumberVar Index;

If Not IsNull(YourField) then
(
    AddressParts := Split({YourField}," ");
    StreetNumber := AddressParts[1];
    If UBound(AddressParts] >= 2 then
        StreetName := Replace(AddressParts[2],",","");
    If UBound(AddressParts] >= 3 then
        For Index := 3 to UBound(AddressParts) do
             UnitNumber := UnitNumber & " " & AddressParts[Index];
)
""

Open in new window


To display them in the report use 1 formula per part
WhilePrintingRecords;
Global StringVar StreetNumber;
StreetNumber

Open in new window


Similar formulas for the other 2 parts

mlmcc
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:ISBTECH
ID: 38721303
@ mlmcc, I paste that into a formula and I get the following error:
12-26-2012-10-03-09-AM.png
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 38722369
Change the ] to a )

It has the same problem a couple of lines later

WhilePrintingRecords;
Global StringVar Array AddressParts;
Global StringVar StreetNumber;
Global StringVar StreetName;
Global StringVar UnitNumber;
Local NumberVar Index;

If Not IsNull(YourField) then
(
    AddressParts := Split({YourField}," ");
    StreetNumber := AddressParts[1];
    If UBound(AddressParts) >= 2 then
        StreetName := Replace(AddressParts[2],",","");
    If UBound(AddressParts) >= 3 then
        For Index := 3 to UBound(AddressParts) do
             UnitNumber := UnitNumber & " " & AddressParts[Index];
)
"" 

Open in new window

0
 

Author Closing Comment

by:ISBTECH
ID: 38723758
Amazing as always!  Thanks!
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

722 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