Monday, September 29, 2014

Crystal Reports : Selection Logic Unleashed

Here is a nice technique to use when your selection criteria starts to get out of control; offload the "heavy lifting" to a formula, then just reference that formula within the Selection Expert.

For instance, let us imagine our Selection Criteria needs to test for multiple things; {CONTACT.STATE} should be either NY, PA or NJ, AND {CONTACT.SOURCE} should be "XMAS 2011" AND {CONTACT.LASTESTIMATE} is at least $100 but no more then $500.

Now, the Selection Criteria for that would look something like this;
{CONTACT.STATE} IN ['PA', 'NY'] AND {CONTACT.SOURCE} LIKE "*XMAS 2011*"
AND
({CONTACT.LASTESTIMATE} >= 100 AND {CONTACT.LASTESTIMATE} <= 500)

Note the use of enclosing parenthesis around the last two conditions; we want the LASTESTIMATE to be BOTH greater than 100 and less than 500.

But you are a Crystal Reporter, and know deep in your heart that someday, someone will need you to change this report. Here is how I would handle the same situation; I would create a separate formula for each condition, thusly;

{@frmState}
IF {CONTACT.STATE} IN ['PA', 'NY'] THEN TRUE ELSE FALSE

{@frmSource}
IF {CONTACT.SOURCE} LIKE "*XMAS 2011*" THEN TRUE ELSE FALSE

{@frmEstimate}
IF {CONTACT.LASTESTIMATE} >= 100 AND {CONTACT.LASTESTIMATE} <= 500 THEN TRUE ELSE FALSE

Now, once those formulas are created (and can be viewed right within the report itself, making troubleshooting very easy), you can use them in the Selection Criteria like this;

{@frmState} = TRUE AND {@frmSource} = TRUE AND {@frmEstimate} = TRUE

This leaves lots of room for compounding, making changes, and plugging in the eventual Parameters. Try it!

1 comment:

Anonymous said...

For lots of, dealing with that appeal to a glossy, replica dior bags unique truck for one truck 3 to 4 years of age is definitely the mature right decision. Caused by programs fault court, replica watches uk trucks assembled within the last few four years are equally simply because dependable simply because brand-new trucks. They will likely possibly interact with the conditions onto your series, and even cost you available 33 % to a unique truck. cartier replica At long last, booking an alternative truck will be an preference if you can not propose to retain the truck for many years, replica hublot though be ready to start looking outside that used monthly installment to grasp the real cost you. replica gucci That theft in computing devices in total in addition to that belonging to the creation belonging to the UNIVERSAL SERIES BUS splash forces replica gucci taken anxiety as a result of a number of suppliers and even those people similarly.