Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2303
  • Last Modified:

Check String for Null value and empty string""

I have a question for crystal Report.
If I want to check if field has null value or empty string “” in formula  how to do it properly?
Let say field has null value but I do not know it.

If I do check on this way:
 
if IsNull({somefield}) OR {Somefield} = ""  then
    Name:="A"
    Else
    Name:="B";
I will get value "A" if filed has null value.

But if I do this check on this way:
If {Somefield} = ""   OR  IsNull({somefield})  then
    Name:="A"
    Else
    Name:="B";
 I got not A not B as result when I put this formula in report. I got  just empty field I assume that formula returning null.

Why both ways not working and giving me same result “A” when filed has null value? I tried to use bracket but not help.

 And what if filed has some other not visible character in as Chr(10), Chr(13) Chr(9) … In first case will formula check if is not null and exit saying is not null and show me “B” and not go to check if filed has value empty string  ""??
0
Taras
Asked:
Taras
3 Solutions
 
vastoCommented:
With Crystal you always need to check for null value before to do anything else. If the value is null and you check it for something else Crystal engine will stop the execution and any code after will be completely ignored. It is like an error, but it is not thrown.
0
 
mlmccCommented:
A little more explanation.

NULL is actually the absence of a value so it is not possible to compare it to a value.

The value Crystal returns on the termination is not defined so it could be anything.  In my experience it is generally no value but according to the write up in Crystal the value is not defined.

IN your case since there is difference between the result for NULL and "" you could use the dropdown that controls how NULLs are handled.  By default the control is EXCEPTION FOR NULLS.  If you have the dropdown in the formula editor you could set it to DEFAULT VALUE FOR NULLS then you won't have to test for NULL and can simply test for the empty string.

There is also a report level option to convert NULLs to a default value which you could set if you don't need to distinguish between a NULL value and the empty string or for numbers 0

mlmcc
0
 
James0628Commented:
And what if filed has some other not visible character in as Chr(10), Chr(13) Chr(9) … In first case will formula check if is not null and exit saying is not null and show me “B” and not go to check if filed has value empty string  ""??
The first formula would give you "B", because neither test is true.  The field contains characters, so it's not null, so the first test is false.  And characters that aren't directly visible, like a line feed, are not the same as an empty string or space.  ChrW (10) <> ""  (You can put that in a formula and see the result for yourself)  So the second test is also false, so you'd get "B".

 If you want to test for a string that is not empty/blank, but does not contain any "visible" characters, you'd need to do that a different way.

 James
0
 
TarasAuthor Commented:
Thanks a lot to all of you guys.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now