Link to home
Start Free TrialLog in
Avatar of MikeM670
MikeM670

asked on

Formula Returns blank lines along with correct data

Crystal Reports 2016
MS SQL

The problem I have is a formula that produces blank results along with the appropriate value.  You can see the blank spaces as  highlighted blue lines.  See image 1
User generated image  

In this example I am looking at a specific record.  In the finalized report I will be looking at records based on dates.  But to simplify this example I am using a specific test record.

Record Selection Formula:
{CivilPMaster.CivilPYear} = 2018 AND {CivilPMaster.CivilPID} = 241

The formula I used to display the Plaintiff's Name.  

Formula: Plaintiff
IF {CivilPPersons.Involvement} = 'PLAINTIFF'
THEN {CivilPPersons.Name} & ', ' & {CivilPPersons.Given1} & ' ' & {CivilPPersons.Given2}

Table: CivilPPersons

CivilPYear int
CivilPID int
Sequence int ( Not Really Needed just using for reference.)
PersonID int ( Not Really Needed just using for reference.)
Business char ( Not Really Needed just using for reference.)
Name varchar
Given1 varchar
Given2 varchar
Given2 varchar
Involvement varchar

Here is a view of the sql results in manager.

User generated image
The number of lines both with data and blank corresponds with the number of lines shown in the sql results.  Is this coincidence?
Avatar of Ido Millet
Ido Millet
Flag of United States of America image

An expression that contains null values returns a null value...
Check for NULL values using IsNull().
Avatar of Mike McCracken
Mike McCracken

Agree.

Another way to do it is in the formula there should be a dropdown that says ERROR FOR NULL change to the other option DEFAULT VALUE FOR NULL

IF {CivilPPersons.Involvement} = 'PLAINTIFF'
THEN IsNull({CivilPPersons.Name},' ') & ', ' & IsNull({CivilPPersons.Given1}, ' ') & ' ' &  IsNull({CivilPPersons.Given2}, ' ')

Open in new window


You probably only need it on the middle initial

mlmcc
Avatar of MikeM670

ASKER

I get an error for your suggestions.  To many arguments given for this function.

IF {CivilPPersons.Involvement} = 'PLAINTIFF'
THEN IsNull({CivilPPersons.Name},' ') & ', ' & IsNull({CivilPPersons.Given1}, ' ') & ' ' &  IsNull({CivilPPersons.Given2}, ' ')

Open in new window

IsNull() doesn't accept a second argument.
Just use IF IsNull({YourField}) Then ... ELSE ...

or Use IIF(IsNull({YourField}), result if true, result if false)
Ok...not sure we are going down the right path here.  I can check for Nulls even tho there are no actual nulls in the actual data.  See original posting.  The issue is there is only one person who is a plaintiff.  But the formula returns lines for all five persons in the database where it should just return the one.  The other four lines are blank.
Change your record selection formula from
{CivilPMaster.CivilPYear} = 2018 AND {CivilPMaster.CivilPID} = 241

Open in new window

to
{CivilPMaster.CivilPYear} = 2018 AND {CivilPMaster.CivilPID} = 241 AND {CivilPPersons.Involvement} = 'PLAINTIFF'

Open in new window

That did work.  However I also need to find the person who is a Defendant.  I would use the same formula but replace 'Plaintiff' with 'Defendant'.  So when I did
{CivilPMaster.CivilPYear} = 2018 AND {CivilPMaster.CivilPID} = 241 AND ({CivilPPersons.Involvement} = 'PLAINTIFF' or {CivilPPersons.Involvement} = 'DEFENDANT')

Open in new window


it now returns two lines.  I Not sure I understand why this happens since I'm using a formula to only display the line that contains "Defendant"

Beginning to think I can't do it this way.  Will I have to use a sub report for each of these?

For reference here is what I am trying to design.  A daily register of transactions that occurred.  
User generated image
If you don't want to see both records, Group by {CivilPMaster.CivilPID}, suppress the detail section, and show the information you want in the Group Footer.
ASKER CERTIFIED SOLUTION
Avatar of MikeM670
MikeM670

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial