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() + " " + Trim(Iif( IsNull() , Trim() + " " , " " ) ) + Trim() 
I know the solution is
If IsNull() Then Trim() + " " + Trim() Else Trim() + " " + Trim() + " " + Trim() 

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

SarekOfVulcan asked Feb 10, 2009 at 20:04 SarekOfVulcan SarekOfVulcan 1,358 5 5 gold badges 16 16 silver badges 36 36 bronze badges

I don't have CRXI handy today, but what doesn't work about the first one? Does it just get the spacing wrong (which is a logic error in the code - you have an extra Trim() in there) or does it fail in some other way?

Commented Feb 10, 2009 at 22:58

For records where .Middle is NULL, CR can't evaluate the string value in Trim(.Middle), and decides the value of the Iif is NULL, even though I have that explicit test in there.

Commented Mar 4, 2009 at 17:30

4 Answers 4

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.

answered Jan 7, 2011 at 16:07 Dev Programmer Dev Programmer 111 1 1 silver badge 3 3 bronze badges

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