Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Multiple "OR" operators Post Reply Post New Topic
Author Message
ameza1983
Newbie
Newbie
Avatar

Joined: 26 Sep 2011
Online Status: Offline
Posts: 5
Quote ameza1983 Replybullet Topic: Multiple "OR" operators
    Posted: 26 Sep 2011 at 7:39am
An example of my situation:

I have a list of dogs. They can be black, grey, white, or brown and some have multiple colors in their fur :-)

When I run a report, I want to be able show all dogs that have the colors I choose. So, lets say I want to see brown, black and white. The report needs to show all dogs with those colors anywhere on them. Even if they have two colors.

When the data for color is input, it is input as Y or N, for some reason this was how our database was designed. So example, when a new dog is input, someone goes down the line and checks Y or N for each color on the dog.

My first instinct is to have a formula that says:

color(brown) = parameter(brown) OR color(black) = parameter(black) OR color(white) = parameter(white)

But this formula stops working past two parameters.

What is the correct way to set up a formula like this where each record may have more than one "description"?

I've been working on this forever and I'm just not good enough! BTW, the dog situation is an example not the real problem. I'm dealing with subcontractors that have multiple business classes.

Thanks!
IP IP Logged
CircleD
Senior Member
Senior Member
Avatar

Joined: 11 Mar 2011
Location: United States
Online Status: Offline
Posts: 251
Quote CircleD Replybullet Posted: 26 Sep 2011 at 7:47am
Try replacing the "or" with "and"
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Sep 2011 at 8:08am
I think the OR is the correct approach as you want all results that meet any color condition entered.
does your DB have nulls? This can interupt the expected results and kill a formula...
IP IP Logged
ameza1983
Newbie
Newbie
Avatar

Joined: 26 Sep 2011
Online Status: Offline
Posts: 5
Quote ameza1983 Replybullet Posted: 26 Sep 2011 at 8:33am
Yes, replacing "or" with "and" makes it too defining. It then will only show companies that are ALL of the "and", for example:

Color = blue AND color = brown will only show ones that are Blue & Brown, but not ones that are simply Brown.

There are nulls, but they have been defined " " is null.

I guess I'm surprised that noone has ever needed a report that basically lets them put checks in a number of boxes and then the report only shows results that have the selections.

Maybe this is outside the realm of crystal reports....
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Sep 2011 at 9:12am

It can be done but you have to deal with NULLs.

1. In your DB you have 1 column per color per 'dog' /(row), correct? If the dog is blue what gets inserted into the blue column?
2. What data type are your parameters? Boolean with color labels?
IP IP Logged
ameza1983
Newbie
Newbie
Avatar

Joined: 26 Sep 2011
Online Status: Offline
Posts: 5
Quote ameza1983 Replybullet Posted: 26 Sep 2011 at 10:05am
If the dog is blue, it gets a "Y".
The actual way it's input is there is a form where a person creates a "dog" and puts check marks in all of the boxes of "colors" that apply. In crystal, these appear as Y or N from what I can tell. Checked being a Y and unchecked being a N.

So when I run the report I can say " show me if the blue parameter = Y OR grey parameter = Y" and it works. As soon as I introduce another "OR" into the situation and one of the parameters is set to "N" then it just return ALL results.

Summary of my example:

Blue Y
White Y
Brown Y

As parameters in report, returns what I want. All dogs that have these and no other.

Blue Y
White Y
Brown N

As parameters now returns ALL dogs that are not Brown, but ignores that I want Blue and White.

i may be a lost cause, this is so hard to explain :-(
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Sep 2011 at 10:17am

I am going to guess these are all boolean fields and your paramters are also boolean.

In the select expert Formula editor chnge the pick list option from 'Exceptions for Nulls' to 'Default Values for Nulls'. This will make all NULLs in the DB appear as a 'false' for the select expert.
Your select statment should then be something like
{?ParamBlue}={table.Blue}
or
{?ParamRed}={table.Red}
or
{?ParamGreen}={table.Green}
or
...
 
 


Edited by DBlank - 26 Sep 2011 at 10:17am
IP IP Logged
ameza1983
Newbie
Newbie
Avatar

Joined: 26 Sep 2011
Online Status: Offline
Posts: 5
Quote ameza1983 Replybullet Posted: 26 Sep 2011 at 11:20am
Thanks!
It must have had something to do with Nulls.
It seems to work correctly now. I had the formula right, but it had something to do with Nulls.

Thanks again!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Sep 2011 at 11:36am
Glad you got it to work  Thumbs%20Up

FYI - if you have NULLs in your DB and you do not tell crystal what to do with the NULLs (various locations to do this) it can stop evaluating the formula when it hits a NULL. When you changed the formula to 'use default values for Nulls' it allows the formula to interpret the Nulls as False for the booleans and therefore continue to evaluate the whole row for all conditions and return the correct rows.

Just want to make sure you understand why it is working now as this will trip you all over the place in crystal if you are not aware of it
 
IP IP Logged
ameza1983
Newbie
Newbie
Avatar

Joined: 26 Sep 2011
Online Status: Offline
Posts: 5
Quote ameza1983 Replybullet Posted: 27 Sep 2011 at 3:37am
Thank you very much for your help and time. I really appreciate you and this site!

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.