Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: using parameters in conditionals Post Reply Post New Topic
Author Message
kev921hs
Newbie
Newbie


Joined: 30 Oct 2007
Online Status: Offline
Posts: 6
Quote kev921hs Replybullet Topic: using parameters in conditionals
    Posted: 30 Oct 2007 at 9:08am
Hi all -
 
I'm new to Crystal Reports XI, and have basic SQL knowledge.  I'm trying to use a boolean parameter field conditionally, as follows:
 
- a boolean parameter prompts "Use only producing wells?" and user selects True/False.  then my attempt at a formula in the select expert is something to the effect of:
 
if {?Producing_Only} = True then {Wells.Status} = 3
else {Wells.Status} = *
 
There are a few other possible states aside from Producing; I'm trying to create a report that will allow the user to either look at just Producing wells, or default to all wells regardless of status.  Is this even possible?  Is there a way around it to get the same functionality?
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet Posted: 30 Oct 2007 at 12:21pm
You should be able to pass the parameter to your Record Selection Formula. If you have created the SQL command to select the records. Then add the the first line
 
IF {?Producing_Only} = True THEN{Wells.Status} = 3;
 
That should be all you need.  If for some reason it fails you can add a line that is something like this
 
IF {?Producing_Only} = FALSE THEN{Wells.Status} IN (3,4,5, etc);
 
Hope this helps.
 
Regards,
 
John W.
 
IP IP Logged
kev921hs
Newbie
Newbie


Joined: 30 Oct 2007
Online Status: Offline
Posts: 6
Quote kev921hs Replybullet Posted: 30 Oct 2007 at 12:39pm
Thanks for the tip, I actually found a way around it a few minutes before you posted using a select case block in a formula and letting it make the decision rather than putting the logic right in the parameter field.  I also used strings instead of booleans...
Just to see if I understand what's going on here though, originally I was adding the if statement as shown to the select formula.  It correctly selected producing wells but if you chose "no" it returned no results, because there was no else clause to handle anything other than "yes".  So naturally I was trying to figure out a way to say "else, select all" or something to that effect.  Eventually I realized I was thinking more in terms of a formula, not a select statement, which is why I went that route...
I guess the question I'm getting to is this: in Crystal, is it incorrect to put logical or conditional statements in the Select Expert?
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 30 Oct 2007 at 4:57pm
Here's what I would do:
 
if {?Producing_Only} then {Wells.Status} = 3
else True
 
Note that when you're working with a boolean value, it is redundant to include "= true" or "= false".  The "phrase" with the "=" in it evaluates to a boolean value, so why not just use the original value itself?
 
-Dell
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 30 Oct 2007 at 9:21pm
One other thing to consider is that John and Dell are using SELECT statements to implement the logic. This passes the work down to the server and produces much more efficient reports. If you are putting the logic in the report selection formula, there is a good chance that the report is doing the filtering and this can take much longer. You can check this by doing a Show Query and look to see if CR is passing the selection formula down to the server or whether it does it to all the data once it gets to the client side.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
kev921hs
Newbie
Newbie


Joined: 30 Oct 2007
Online Status: Offline
Posts: 6
Quote kev921hs Replybullet Posted: 31 Oct 2007 at 1:26pm

Dell,

Your suggestion did it, and it is much simpler than what I'd come up with.  Thanks!

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.