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 Mike Lewis 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 '0000' problem!! Brain Fried!!

Status
Not open for further replies.

DeviousDi

MIS
May 23, 2013
57
GB
Hi,

I don't know whether I'm looking at this and missing something obvious, or my brain has just given up for the week!

I am trying to basically add a description field to a report, based on another field.

Here's a summary of the data:

if {debtor_freefields.ff2} = "0000" THEN "Default" else
if {debtor_freefields.ff2} = "D00" THEN "PEST - Default" else
if {debtor_freefields.ff2} = "D01" THEN "PEST - Michael Green" else
if {debtor_freefields.ff2} = "D02" THEN "PEST - Scott Friday" else
if {debtor_freefields.ff2} = "D03" THEN "PEST - Sean Murray" else
if {debtor_freefields.ff2} = "D04" THEN "PEST - Andy Rayland" else "Not yet set"

The problem being, is that the if statement isn't working for "0000" and returns "Not yet set" instead of "Default". Debtor_freefields.ff2 is alphanumeric, so as far as I can see, there shouldn't be a problem!

What am I missing that's glaringly obvious?! I would like to add, that I have been up for over 36 hours, so brain may be a little fried!

Thank you!

Di

[neutral]

 
Perhaps you need to Trim the field to remove spaces. Or perhaps it contains invisible characters that you need to remove (using Replace).
Place the field on the report canvas, Preview, copy, and paste into a text editor (Notepad++) and use View, Show All Characters...

hth,
- Ido


view, export, burst, email, and schedule Crystal Reports.
 
Hi,

Checked, no spaces, invisible characters or anything else!

I'm scuppered! Have used the same formula on three other fields that hold similar info, and its worked fine no problems.

Losing the will to live!
 
Just for testing sometimes I have just created a formula like len({debtor_freefields.ff2}) just to make sure I am not going crazy. You might want to do a trim({debtor_freefields.ff2}) just because it shouldn't hurt anything.
 
Probably unlikely, but have you checked it is 4 (numeric) zeros, not 4 uppercase (alpha) Os?

Just a thought.

Pete
 
Some examples might help.

This example works as shown. No conversions take place.
Code:
if {Command.col1} = "0000" THEN "Default" else 
if {Command.col1} = "D00"  THEN "PEST - Default" else 
if {Command.col1} = "D01"  THEN "PEST - Michael Green" else 
if {Command.col1} = "D02"  THEN "PEST - Scott Friday" else 
if {Command.col1} = "D03"  THEN "PEST - Sean Murray" else 
if {Command.col1} = "D04"  THEN "PEST - Andy Rayland" 
else "Not yet set"

This example fails displays "Not yet set" as shown. Conversions take place.
Code:
if {Command.col1} = totext(0000,0,'') THEN "Default" else 
if {Command.col1} = "D00"  THEN "PEST - Default" else 
if {Command.col1} = "D01"  THEN "PEST - Michael Green" else 
if {Command.col1} = "D02"  THEN "PEST - Scott Friday" else 
if {Command.col1} = "D03"  THEN "PEST - Sean Murray" else 
if {Command.col1} = "D04"  THEN "PEST - Andy Rayland" 
else "Not yet set

This example fixes the conversions by padding the 0000 a number to "0000" a string.
Code:
if {Command.col1} = left(totext(0000,0,'')+'0000',4) THEN "Default" else 
if {Command.col1} = "D00"  THEN "PEST - Default" else 
if {Command.col1} = "D01"  THEN "PEST - Michael Green" else 
if {Command.col1} = "D02"  THEN "PEST - Scott Friday" else 
if {Command.col1} = "D03"  THEN "PEST - Sean Murray" else 
if {Command.col1} = "D04"  THEN "PEST - Andy Rayland" 
else "Not yet set"

Code:
select '0000' as col1
union
select 'D00'  as col1
union
select 'D01'  as col1
union
select 'D02'  as col1
union
select 'D03'  as col1
union
select 'D04'  as col1
 
Thanks all!!!

Pmsawyer, you got it right! lol

All sorted finally!

Thank you again for your help

Di

[wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top