Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Record selection formula Post Reply Post New Topic
Author Message
paulpo
Newbie
Newbie


Joined: 03 Oct 2011
Online Status: Offline
Posts: 2
Quote paulpo Replybullet Topic: Record selection formula
     Posted: 03 Oct 2011 at 7:29pm
Trying to use this code fragment to include or exclude records based on a user Boolean parameter (?Include OT)  selection. When the parameter is False, it correclty excludes records with Modality.OT and also selects based on the ?Dates range. But when parameter ?Include OT is True, it correctly includes records where Modality is OT, but it ignores the "and" statement selecting on a date range. Since the 'if' and 'else' statements are single lines, i don't need parethesis to ensure the "and" statement is evaluated regardless of the parameter is True or False do i? what else am I missing? Thanks very much for any suggestions.
 
if {?Include OT} then
{DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US", "OT"]else
{DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US"]
and
Date({DoctorDetail_Backup.InputDateTime}) in minimum({?Dates}) to maximum({?Dates})
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 03 Oct 2011 at 8:22pm
The if- then statement treats the code between "then...else" and "else...end" as completely seperate. You want the date range test to be evaluated in both the true and false code blocks, but you only have it listed in the Then code block. It can't be shared between the two. Thus, you need to use it in both places. And as a general rule I always use parentheses b/c it makes your code easier to understand, debug and maintain in the future.

if {?Include OT} then
({DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US", "OT"]
and
Date({DoctorDetail_Backup.InputDateTime}) in minimum({?Dates}) to maximum({?Dates}))
else
({DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US"]
and
Date({DoctorDetail_Backup.InputDateTime}) in minimum({?Dates}) to maximum({?Dates}))

Brian
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
paulpo
Newbie
Newbie


Joined: 03 Oct 2011
Online Status: Offline
Posts: 2
Quote paulpo Replybullet Posted: 04 Oct 2011 at 6:45am
thanks very much.  The code example i listed is a bit simpler than the actual selection criteria. In addition to repeating the Date selection code there would be other selection fields like Doc names, Shift Work times etc. It would make for a lot of redundant code to put it in both the if and else sections. If it isn't a problem to have the redundancy, then that's what I'll do. Thanks very much again for the ultrafast response.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 04 Oct 2011 at 7:00am
IMO avoid the if-then in the select statment altogther:
 
Date({DoctorDetail_Backup.InputDateTime}) in minimum({?Dates}) to maximum({?Dates})
and
(
(
{?Include OT} and {DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US", "OT"]
)
or
(
NOT({?Include OT}) and {DoctorDetail_Backup.Modality} in ["CR", "CT", "MR", "NM", "US"]
)
)
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