Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula for zipcodes

Status
Not open for further replies.

bld21

Technical User
Mar 1, 2010
49
US
I am using crystal reports 2008, and I have a field that contains 9 digits for the zipcode. I would like to display the data as 12345-6789
and 12345 if there is no last 4 digits
and 12345 if the last 4 digits are 0000
without the - sign.

Any ideas? I am a new user to crystal.
Thanks!
 
I think I am almost there. I am getting a boolean required error. See my formula below


(If {customer_address.postal_cde}[6 to 9] = "0000" then
{customer_address.postal_cde}[1 to 5] else
{customer_address.postal_cde}[1 to 5] + "-" + {customer_address.postal_cde}[6 to 9])
 
you did not say what your datatype is in the database, so i am going to guess it is numeric and go from there...


numbervar lenzip := len(totext({table.zipcode});
stringvar longzip;

IF lenzip =5 then longzip := totext({table.zipcode})
else
(
IF instr({table.zipcode},"0000")>0
then longzip := left(totext({table.zipcode}),5)
else longzip := left(totext({table.zipcode}),5)&"-"&right(totext({table.zipcode}),4)
);
 
A couple of modifications and it worked for me.
I also added a check for 5 digit zips so that you don't end up w/a '-' at the end of those that are not 9 digits.


IF len(totext({customer_address.postal_cde}))=5
then totext({customer_address.postal_cde})
else
(If "0000" in {customer_address.postal_cde}[6 to 9] then
totext({customer_address.postal_cde})[1 to 5] else
totext({customer_address.postal_cde})[1 to 5] & "-" & totext({customer_address.postal_cde})[6 to 9])
 
I tried to use the code above and I am getting the error " The result of the selection formula must be a boolean".

What does this mean exactly and how would I correct the formula.

Thanks!
 
You should be creating the formula in the field explorer->formula->new, NOT in the selection formula area.

-LB
 
Yes that was it! Thanks a million. I have a lot to learn...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top