Search code examples
databasecrystal-reportsfieldcrystal-reports-2008

Conditional printing depending of empty or null value in Crystal Reports


Suppose I have an StoredProcedure that returns a unique row corresponding to a table with columns "Name" and "Surname".

I want the report to show:

Name: NameField
Surname: SurnameField

Where the "NameField" and "SurnameField" are the fields returned by the StoredProcedure.

The special requirement, is that if "SurnameField" is empty or null, then I don't want to show the "Surname: SurnameField".

How can I achieve this? The only thing that I thought is breaking the storedprocedure in two, one for Name and one for Surname, and dividing each line in different subreports and selecting "Delete if empty" (or something like that) for the second... but this is really overkill, I guess there's an easier way.


Solution

  • Should be quite a few ways of achieving this. I'm not quite sure how your report is laid out but you can surpress the field and label or entire section (if it has it's own) using a simple formula; isnull({table.field}) or {table.field} = ''

    Or if you have set nulls to be treated as defaults rather than exceptions you can simply do: {table.field} = ''

    L