Crystal Reports for Rational Application Developer Designer Guide

Switch (expr1, value1, expr2, value2, …)

Sample report
A more complete version of the example, with 27 Switch conditions, is provided with the sample report named "Record Selection on DateRange.rpt."
Sample reports are located in the Crystal Reports directory under \Samples\En\Reports.
When you preview the report, you supply a reference order date parameter, {?reference date} and a range condition, {?reference condition} to indicate a range of dates around the reference order date. The report is then previewed with only the records whose order dates fall in the specified range.
The entire record selection is performed on the database server. This is because the Switch function and all its arguments can be evaluated before accessing the database.
Note:
  • In this sample report, the Switch function is returning a Date Range value.
  • The indentation style of the code makes the Switch function call look similar to a control structure and makes reading the function easier.
  • The last expression is the Boolean value True.
This Switch function call provides for an explicit default value since if none of the other expression are True, the last expression is automatically True, and so the Date Range CDate (1899, 12, 30) To CDate(1899, 12, 30) is returned.
//Crystal syntax record selection formula
{Orders.Order Date} in
Switch
(
     {?reference condition} = "Aged 0 to 30 days",
          ({?reference date} - 30) To {?reference date},
     {?reference condition} = "Aged 31 to 60 days",
          ({?reference date} - 60) To ({?reference date} - 31),
     {?reference condition} = "Aged 61 to 90 days",
          ({?reference date} - 90) To ({?reference date} - 61),
     True, // provide default handling and specify a valid range
          CDate(1899, 12, 30) To CDate(1899, 12, 30)
)



Business Objects, an SAP company
http://www.businessobjects.com/
Support services
http://www.businessobjects.com/services/support/
Product Documentation on the Web
http://support.businessobjects.com/documentation/