stripping data from a Varchar feild in Crystal 2008

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"
ISBTECHAsked:
Who is Participating?
 
mlmccConnect With a Mentor Commented:
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
 
rmailCommented:
You could break the string on the first space and the word 'unit':
http://stackoverflow.com/questions/697519/split-function-equivalent-in-tsql
0
 
hpdvs2Commented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
mlmccCommented:
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
 
ISBTECHAuthor Commented:
@ mlmcc, I paste that into a formula and I get the following error:
12-26-2012-10-03-09-AM.png
0
 
ISBTECHAuthor Commented:
Amazing as always!  Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.