Crystal Reports If true then return number else return NULL
In Crystal Reports, is it possible to have a function that returns a numeric value if the if statement evaluates to true and returns NULL otherwise?
I currently have
IF ({INDICATOR} = 'Y') Then
(
{numeric value}
)
Else
(
0
);
But since 0 is a possible value {numeric value}, it doesn't make sense. Rather, I would prefer this field to look empty unless the indicator is "Y", but when I replace 0 with NULL it gives me a type mismatch error.
Is there a way to show only the value when the indicator is "Y"?
source to share
you cannot return two different data types in the same expression if
. If if
is a number, then there should still be a number .. instead try to split the operators and try .. something like below.
IF ({INDICATOR} = 'Y') Then
(
ToText({numeric value})
)
Else if ({INDICATOR} <> 'Y') Then
(
""
);
source to share
If {INDICATOR} = 'Y' then {numeric value}
else {Command.NULLCOL}
The setting in Database Expert is to use the Add command from sql:
select null as nullcol
from dual
Then left join with it.
The returned null value can be very powerful, so your need for a null value shouldn't be questioned. Zero values ββare automatically displayed in different ways to stand out. Compared to 0 or "", null values ββwork correctly with the DistinctCount function. Zero values ββalso work correctly with section summaries and crosstabs, which can save you a lot of work, which is the whole point of using a crystal.
source to share