Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crystal Reports formula: IsNull + Iif

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...

like image 929
SarekOfVulcan Avatar asked Feb 10 '09 20:02

SarekOfVulcan


2 Answers

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...

like image 64
Dev Programmer Avatar answered Sep 22 '22 17:09

Dev Programmer


I know I'm years late on this one, but I came upon this question while trying to figure out the same thing. Funny enough, I couldn't even find the answer in Crystal Reports documentation, but instead in a link to IBM.

Baiscally, if you're using Crystal Reports 8.x or 10.x, ISNULL and IIF don't work together. From the site:

Cause

There is a defect in Crystal Reports 8.x and 10.x that prevents the above formula from working correctly. The 'IIF' and 'IsNull' commands cannot function together, and that includes attempting to use "Not" to modify the IsNull command; for example, IIF(Not IsNull ()).

Resolving the problem

The workaround is to use an "If-Then-Else" statement. For example,

If IsNull({~CRPT_TMP0001_ttx.install_date}) Then "TBD" Else "In Progress"

So if you're using CR 8.x or 10.x (which we are), you're out of luck. It makes it REAL fun when you are concatenating multiple fields together and one of them might be NULL.

like image 33
LittleBobbyTables - Au Revoir Avatar answered Sep 18 '22 17:09

LittleBobbyTables - Au Revoir