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!

If Then Else in Crystal Report Formula

Status
Not open for further replies.

acabrera

Programmer
Jan 22, 2004
44
US
I have a Crystal Report where I use the IF-THEN-ELSE to decode a field. The formula field, PHONETYP, is based on the database field DETAIL_CD. Previously, I included PHONETYP in the statement below but it was not accepted. Below is the IF statement which has no compile error but which does not take effect in the report.

if {ECON_DETAIL_V.DETAIL_CD}="EMG_F" then
"Emg Pager"
else if {ECON_DETAIL_V.DETAIL_CD}="EMG_P" then
"Emg Home"
else if {ECON_DETAIL_V.DETAIL_CD}="EMG_C" then
"Emg Cell"
else if {ECON_DETAIL_V.DETAIL_CD}="PHONE" then
"Office"
else if {ECON_DETAIL_V.DETAIL_CD}="PAGER" then
"Emg Pager"
else if {ECON_DETAIL_V.DETAIL_CD}="HPHN" then
"Emg Phone"
else
{ECON_DETAIL_V.DETAIL_CD}
 
Meaning that it returns a null, or?

Try testing using:

if uppercase(trim({ECON_DETAIL_V.DETAIL_CD}))="EMG_F" then
"Emg Pager"
else
if...etc...
else
trim({ECON_DETAIL_V.DETAIL_CD})+" was not found"

Explicitly trimming and forcing the uppercase might do it, and returning explicit text if nothing is found might help you identify the error"

-k
 
Check for nulls first
if isnull({ECON_DETAIL_V.DETAIL_CD}) then
""
else if {ECON_DETAIL_V.DETAIL_CD}="EMG_F" then
"Emg Pager"
else if {ECON_DETAIL_V.DETAIL_CD}="EMG_P" then
"Emg Home"
else if {ECON_DETAIL_V.DETAIL_CD}="EMG_C" then
"Emg Cell"
else if {ECON_DETAIL_V.DETAIL_CD}="PHONE" then
"Office"
else if {ECON_DETAIL_V.DETAIL_CD}="PAGER" then
"Emg Pager"
else if {ECON_DETAIL_V.DETAIL_CD}="HPHN" then
"Emg Phone"
else
{ECON_DETAIL_V.DETAIL_CD}
 
I reviewed the report design again and found out that I had not replaced the database field with the formula field. When I did, the report was ok. Thanks.
 
Dear acabrera,

Glad it is working ... and suggest you look at using Case formulas as they are easier to read... You could change your formula to, in my testing the isnull test isn't required because the default (if all the cases are false then default is true) handles and it would print a null since it is printing the value in the field.

Select {ECON_DETAIL_V.DETAIL_CD}
Case 'EMG_F', 'PAGER' : 'Emg Pager'
Case 'EMG_P' : 'Emg Home'
Case 'EMG_C' : 'Emg Cell'
Case 'PHONE' : 'Office'
Case 'HPHN' : 'Emg Phone'
Default : {ECON_DETAIL_V.DETAIL_CD}

I like the case in Crystal because when there are many values to test it is easier to read and easier to write.

Just an fyi,
ro


Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top