I'm fairly new to Crystal Reports, running 2008, and have a general question in the form of a problem that I'm trying to solve: how to avoid repeating blocks of code in the record selection formula.
In the following sample, I have a report that accepts 4 parameters, Cost Center, Location, Cost Center
Begin Date, and Cost Center End Date. The record selection formula varies based on what the user enters for parameters, but the core record selection, based on the date range, remains the same.
Is there a better way to write my record selection formula so that I don't have to repeat portions of the selection formula ?
In my record selection formula, a block of code definining the date range selection critieria, called "BLOCK-A", is repeated 4 times:
If <condition-1> then // match any CC LOC
(BLOCK-A)
else if <condition-2> then // match CC and any LOC
{CostCenter.FullName}={?Cost Center} and
(BLOCK-A)
else if <condition-3> then // match LOC and any CC
{AGENCY_LOCATION.NAME_LINE_1}={?Location} and
(BLOCK-A)
else // match on both CC and LOC
{CostCenter.FullName}={?Cost Center} and
{AGENCY_LOCATION.NAME_LINE_1}={?Location} and
(BLOCK-A)
Is there a better way to design this report or write my record selection formula so that I don't have to repeat "BLOCK-A" 4 times ? I need to add another parameter, which means if I use the current method, BLOCK-A will be repeated even more times.
"BLOCK-A" is:
({CostCtrGrp.AdmitDate}<{@CC_Begin_Date})
OR ({CostCtrGrp.AdmitDate}>={@CC_Begin_Date} and
{CostCtrGrp.AdmitDate}<={@CC_End_Date}
AND (ISNULL({CostCtrGrp.DischargeDate}) OR {CostCtrGrp.DischargeDate} >= {CostCtrGrp.AdmitDate}))
The full record selection formula is below.
If ({?Cost Center}="ALL") and ({?Location}="ALL") then // match any CC LOC
({CostCtrGrp.AdmitDate}<{@CC_Begin_Date})
OR ({CostCtrGrp.AdmitDate}>={@CC_Begin_Date} and
{CostCtrGrp.AdmitDate}<={@CC_End_Date}
AND (ISNULL({CostCtrGrp.DischargeDate}) OR {CostCtrGrp.DischargeDate} >= {CostCtrGrp.AdmitDate}))
else if not ({?Cost Center}="ALL") and ({?Location}="ALL") then // match CC and any LOC
{CostCenter.FullName}={?Cost Center} and
({CostCtrGrp.AdmitDate}<{@CC_Begin_Date})
OR ({CostCtrGrp.AdmitDate}>={@CC_Begin_Date} and
{CostCtrGrp.AdmitDate}<={@CC_End_Date}
AND (ISNULL({CostCtrGrp.DischargeDate}) OR {CostCtrGrp.DischargeDate} >= {CostCtrGrp.AdmitDate}))
else if ({?Cost Center}="ALL") and not ({?Location}="ALL") then // match LOC and any CC
{AGENCY_LOCATION.NAME_LINE_1}={?Location} and
({CostCtrGrp.AdmitDate}<{@CC_Begin_Date})
OR ({CostCtrGrp.AdmitDate}>={@CC_Begin_Date} and
{CostCtrGrp.AdmitDate}<={@CC_End_Date}
AND (ISNULL({CostCtrGrp.DischargeDate}) OR {CostCtrGrp.DischargeDate} >= {CostCtrGrp.AdmitDate}))
else // match on both CC and LOC
{CostCenter.FullName}={?Cost Center} and
{AGENCY_LOCATION.NAME_LINE_1}={?Location} and
({CostCtrGrp.AdmitDate}<{@CC_Begin_Date})
OR ({CostCtrGrp.AdmitDate}>={@CC_Begin_Date} and
{CostCtrGrp.AdmitDate}<={@CC_End_Date}
AND (ISNULL({CostCtrGrp.DischargeDate}) OR {CostCtrGrp.DischargeDate} >= {CostCtrGrp.AdmitDate}))
Thanks!
Ken
Edited by: KenHannan on Apr 27, 2009 6:27 PM
Edited by: KenHannan on Apr 27, 2009 6:29 PM