Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Report Design
Message Icon Topic: and logical operator Post Reply Post New Topic
Author Message
koo9
Newbie
Newbie
Avatar

Joined: 22 Apr 2009
Location: Canada
Online Status: Offline
Posts: 11
Quote koo9 Replybullet Topic: and logical operator
    Posted: 06 Dec 2012 at 4:44am

hi all,

 
when using the AND operator to evaluate two conditions, does CR do the short circuit evaluation? aka if the first expression is false, the second condition won't be evaluated. if that's the case we could write expression like
 
if not isnull(somestringfield) and somestringfield <> "" then
 
instead of using two if statements.
 
Thanks
 
Kevin
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Dec 2012 at 5:04am
I believe it stops evaluating as soon as it hits something that makes it false. So in general you want to use more simple/efficient condition first.
however, null data and how you have it configured to handle nulls will partially imapcts the behavior.
 
If you do not explicitly write in the null handler as the first condition or use the formual editor option to 'use default values for nulls' then the crystal will stop evaluting the fomrula as soon as it hits a null.
 


Edited by DBlank - 06 Dec 2012 at 5:18am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 06 Dec 2012 at 5:55am
to further try and explain the NULL issue in crystal here is an example,
(this example assumes you tha you are not using default values for nulls)
 
isnull(fielda) or fielda=""
 
will not evaluate the same
 
fielda="" or isnull(fielda)
 
the first statement will return "True" for nulls or empty strings and "False" for all other instances.
The second statement will return "True" for empty strings, false for non empty strings and nothing for nulls.
 
the second statement is evaluating fielda for an empty sting first, since we did not tell it how to handle the a null, it just stops evaluating and never gets to the second condition and does not return any value at all.
 
You can place these two formula fields side by side on your report to see how they act differently.
 
If you use the formula editor option setting 'Default values for null' it tells the formual how to handle the null and allows it to continue to check all of the conditions in the formula.


Edited by DBlank - 06 Dec 2012 at 5:56am
IP IP Logged
koo9
Newbie
Newbie
Avatar

Joined: 22 Apr 2009
Location: Canada
Online Status: Offline
Posts: 11
Quote koo9 Replybullet Posted: 06 Dec 2012 at 6:24am
thanks for the detailed explaination. that's why I am using the statement as this one
not isnull(fielda) and fielda<>"",
to make sure the string is not null first then check if the string is empty.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.