Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Need help with a selection formula... Post Reply Post New Topic
Author Message
BadBoyHouse
Newbie
Newbie


Joined: 25 May 2010
Online Status: Offline
Posts: 20
Quote BadBoyHouse Replybullet Topic: Need help with a selection formula...
     Posted: 17 Jan 2011 at 2:29am
I've been asked to create a report based on certain tickboxes within our SQL database.
 
Here is the selection formula:
 
// Exclude Suspended clients and select client show receive a newsletter
({tblClient.Suspended} = FALSE and {tblClientExtraDetails.Newsletter} = "1")
and
// Show clients where Email_Moneyworks is EMPTY or FALSE
(ISNULL ({tblClientExtraDetails.Email_Moneyworks}) OR {tblClientExtraDetails.Email_Moneyworks} = false)
OR
// Show clients where Unsubscribe_Moneyworks is EMPTY or FALSE
(ISNULL ({tblClientExtraDetails.Unsubscribe_Moneyworks}) OR {tblClientExtraDetails.Unsubscribe_Moneyworks} = false)
 
Individually the Email_Moneyworks and the Unsubscribe_Moneyworks fields pick out 456 and 509 records respectively (with one or the other remm'd out).
 
However with both included I get 1463 results.
 
I'm suspecting it's either too many OR's for crystal to handle or my code is wrong somewhere.
 
The first criteria relating to suspended and newsletter must stay.
 
Any ideas much appreciated.
IP IP Logged
JohnT
Groupie
Groupie
Avatar

Joined: 20 Jan 2008
Online Status: Offline
Posts: 92
Quote JohnT Replybullet Posted: 17 Jan 2011 at 3:51am

I suspect the problem is the combination of your "and" and your "or".  Without additional parenthesis, it is difficult to see what you intended. 

Are you looking for ((suspended) and (email or unsubscribed))  or are you looking for ((suspended and email) or (unsubscribed)) ?  I am guessing you want the first one.  If so, I would add another set of parenthesis around the (email or unsubscribe) so that is evaluated together. 
 
Another thing you can do would be to find a record that is in your 1463 total that is not in the (456+509) and see which statement is causing it to appear.   
IP IP Logged
BadBoyHouse
Newbie
Newbie


Joined: 25 May 2010
Online Status: Offline
Posts: 20
Quote BadBoyHouse Replybullet Posted: 17 Jan 2011 at 4:43am

The first section is essential:

// Exclude Suspended clients and select client show receive a newsletter
({tblClient.Suspended} = FALSE and {tblClientExtraDetails.Newsletter} = "1")

THEN, it needs to match EITHER of the following two criteria:


and

// Show clients where Email_Moneyworks is EMPTY or FALSE
(ISNULL ({tblClientExtraDetails.Email_Moneyworks}) OR {tblClientExtraDetails.Email_Moneyworks} = false)

OR

// Show clients where Unsubscribe_Moneyworks is EMPTY or FALSE
(ISNULL ({tblClientExtraDetails.Unsubscribe_Moneyworks}) OR {tblClientExtraDetails.Unsubscribe_Moneyworks} = false)

 

IP IP Logged
Keikoku
Senior Member
Senior Member


Joined: 01 Dec 2010
Online Status: Offline
Posts: 386
Quote Keikoku Replybullet Posted: 17 Jan 2011 at 4:45am
It is an issue with the logic in your statement.

These are the two conditions:

1.Client is not suspended and wants newsletter and doesn't want moneyworks
2.Client has not unsubscribed moneyworks

x AND y OR z is the same as (x AND y) OR z due to AND having greater precedence over OR.

Unless, of course, Crystal doesn't follow boolean standards.

If what I said is true, all you need to write, as suggested above, is

x AND (y OR Z)

That is the same as (x AND y) OR (x AND z)

Edited by Keikoku - 17 Jan 2011 at 4:47am
IP IP Logged
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