Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formula to check if string is empty in Crystal Reports

Tags:

I have written a formula to return a string based on logic run on a string field in my database. I have everything working, except I'm unable to return when the field is the empty string.

This is what I need:

...
else if ({TABLE.FIELD} = "") then
    "Fixed"
...

However, this entry appears as the empty string in my report. I've tried testing the length of the field to 0 and the StrCmp functions. Nothing seems to work. Google results state that a simple comparison to "" or '' should make the logic work. I am new to CR, so maybe I am missing something. Any ideas on how I can acquire this functionality?

like image 713
user3203365 Avatar asked Jan 16 '14 16:01

user3203365


People also ask

How do you check the blank value in Crystal Reports?

You can check for IsNull condition. Although it should be obvious from the answer, you want to check for NULL as your first check, since Crystal Reports is picky about handling nulls. @numerah If IsNull({Table.

Is null in Crystal formula?

Symptom. IIF and IsNull are functions in Crystal Reports that are used in formulas to test fields for blanks, empty strings, missing values and NULL, then return some valid output. This is especially helpful when preparing a report, since these values can cause blank lines to be printed.

IS NOT NULL condition in Crystal report?

@michaelg The purpose of NOT ISNULL is to determine, true or false, should I update the shared variable? If value isn't null, your code should put it into the shared variable. If it is null, your code can safely ignore it and do nothing.

Why does Crystal Reports return odd results with string formulas?

Crystal Reports may return odd results with string formulas that may encounter a database field containing a null value (a special database value equating to empty, as opposed to zero for a number field, or an empty string for a string/text field).

Is a crystal string actually empty and not null?

It's been a long while since I used Crystal, but are you sure it's actually empty and not null? If I recall correctly, Crystal does a very poor job of handling null values, and they must be checked first; check to see if the string is a null as your very first test and display "Fixed", see if that clears things up.

How does Crystal Reports interpret numbers in formulas?

When you enclose the numbers in quotation marks, Crystal Reports interprets the values in the formula as strings, not numbers. When you use a plus sign or ampersand with strings, the result is the concatenation of the individual string elements.

How do I set default values for null in Crystal formulas?

In Crystal formulas there is a dropdown at the top of the screen which asks if you want to "use default values for NULL" or "exceptions for NULL". It is often easier to use default values (you don't then have to check for NULL).


1 Answers

You can check for IsNull condition.

If IsNull({TABLE.FIELD}) or {TABLE.FIELD} = "" then
  // do something
like image 67
Andrew Avatar answered Sep 19 '22 09:09

Andrew