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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formula to format zip codes 1

Status
Not open for further replies.

dpm1234

Programmer
Aug 27, 2003
9
US
Hi,

I'm sure this has been done before so...

I have 5 and 9 digit zip codes stored in a database without any hyphens. I would like to insert one when necessary. Some of the zip codes are not well formed, in that case I would like to do nothing.

i.e.
12345 => 12345
1234567 => 1234567
123456789 => 12345-6789

Anyone have a formula that would do this for me?
 
I'll assume that it's stored as a string:

if len(trim({table.field}) = 9 then
picture({table.field},"99999-9999")
else
{table.field}

-k

 
And if that doesn't work, change the 9's to x's:

if len(trim({table.field}) = 9 then
picture({table.field},"xxxxx-xxxx")
else
{table.field}

-dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top