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

Format string from database

Status
Not open for further replies.

nina1

Programmer
Aug 14, 2001
31
CA
I have a field in database that contains different phone formats depending on different state. So I have to write a formula that is taking a field from database and make the same format on the report. For example I have a field in database for Japan and format is ###-##-##-#### and field for Germany that is ###-###-##-#### and depending what field is coming from database I have to format phone field on the report.
I am using Crystal Reports 8.5.
This is urgent Please....

Thank you
 
You don't state how you want your results. If you want to eliminate the dashes so that only numbers are displayed use:

Replace({phone.field},"-",""}

This will replace all -'s with nothing

123-45-67-8901 will result in 12345678901 Mike

 
I want the same format as in database, but there are more formats (like every country different format), how can I(if I can) write the formula that read database field and make the same format for the phone field on the report.

Thanks!
 
If {Country}=&quot;JAPAN&quot; then <<formula 1>> else
if {Country}=&quot;GERMANY&quot; then <<formula 2>> else.....

continue this logic as long as necessary Software Training and Support for Macola, Crystal Reports and Goldmine
251-621-8972
dgilsdorf@mchsi.com
 
The problem is I don't know what format is in database, because format is custom from the input screens, so I have to find out first what the format is and then format the field in the report.
 
It looks like you're moving the goalposts on dgillz a little bit there, Nina. You said that you want the same format that's in the database, but then later, you said that you want to find out the format that's in the database, so you can reformat it.

If you want the field as it is in the database, you don't need to reformat it. You just report it from the {database.field}.

If it's the case that the database may have formats a little mixed up for certain countries, but you know what the format should be, then I would work with dgillz' formula.

If {Country}=&quot;JAPAN&quot;
Then Picture(Replace({phone.field},&quot;-&quot;,&quot;&quot;),&quot;xxx-xx-xx-xxxx&quot;)
Else
If {Country}=&quot;GERMANY&quot;
Then More.Of.The.Same...

This formula takes the field, and then tries to unformat the string by stripping out all the dashes. The xxx part of the picture command then tells the field what format it should have.

Good luck,

Naith
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top