Crystal Reports formula: IsNull + Iif

SarekOfVulcan picture SarekOfVulcan · Feb 10, 2009 · Viewed 25k times · Source

There are hints of the answer to this question here and there on this site, but I'm asking a slightly different question.

Where does Crystal Reports document that this syntax does not work?

Trim({PatientProfile.First}) + " "
    + Trim(Iif(
        IsNull({PatientProfile.Middle}) 
        , Trim({PatientProfile.Middle}) + " "
        , " "
        )
    )  
+ Trim({PatientProfile.Last})

I know the solution is

If IsNull({PatientProfile.Middle}) Then
    Trim({PatientProfile.First})
        + " " + Trim({PatientProfile.Last})
Else
    Trim({PatientProfile.First})
       + " " + Trim({PatientProfile.Middle})
       + " " + Trim({PatientProfile.Last})

but how are we supposed to figure out we can't use the first version?

The documentation for IsNull says

  • Evaluates the field specified in the current record and returns TRUE if the field contains a null value

and Iif gives

  • [Returns] truePart if expression is True and falsePart if expression is False. The type of the returned value is the same as the type of truePart and falsePart.

I suppose if you stare at that line about "type of the return value" you can get it, but...

Answer

Dev Programmer picture Dev Programmer · Jan 7, 2011

Where does Crystal Reports document that this syntax does not work?

I doubt there is anyplace large enough in the entire universe to document everything that does not work in Crystal Reports...