EVALUATE
Syntax
EVALUATE {any_lit|_var|_col}
This command is equivalent to case/switch in C or Java. The general format of an EVALUATE command is:
EVALUATE {any_lit|_var|_col} WHEN comparison_operator {any_lit|_var|_col} SQR_Command... [BREAK] [WHEN comparison_operator {any_lit|_var|_col} SQR_Command... [BREAK]] [WHEN-OTHER SQR_Command... [BREAK]] END-EVALUATE
Description
Determines the value of a column, literal, or variable and takes action based on that value.
The EVALUATE command is useful for branching to different commands depending on the value of a specified variable or column.
EVALUATE commands can be nested.
Evaluating a date variable or column with a string results in a date comparison (chronological, not a byte-by-byte comparison as is done for strings). The string must be in the proper format as shown in the following list:
-
For DATETIME columns and SQR DATE variables in the format specified by the SQR_DB_DATE_FORMAT setting, SQR uses one of the database-dependent formats (see the Default Database Formats table), or the database-independent format 'SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]'.
-
For DATE columns, SQR uses the format specified by the SQR_DB_DATE_ONLY_FORMAT setting, or the format listed in the DATE Column Formats table.
-
For TIME columns, SQR uses the format specified by the SQR_DB_TIME_ONLY_FORMAT setting, or the format as listed in the TIME Column Formats table.
Parameters
| Parameter | Description |
|---|---|
|
any_lit|_var|_col |
Specifies a text or numeric column; a text, numeric, or date variable; or a text or numeric literal to be used in the evaluation. In short, this is an evaluation argument. |
|
comparison_operator |
Any valid comparison operator. See the list of operators in the #IF command. See #IF. |
|
WHEN |
Specifies the evaluation expression. The evaluation argument is compared with the argument, beginning from the first WHEN. If the expression is TRUE, SQR processes the commands after the WHEN. If the expression is FALSE, SQR processes the next WHEN expression. Each WHEN must be on its own line. If more than one WHEN expression appears directly before a set of commands, any one of them, if TRUE, causes the commands to be carried out. |
|
BREAK |
Causes an immediate exit of the EVALUATE command. Use BREAK at the end of a set of commands. |
|
WHEN-OTHER |
Signifies the start of default commands to be processed if all other WHEN expressions are FALSE. WHEN-OTHER must appear after all other WHEN expressions. |
Example
The following example illustrates the EVALUATE command:
evaluate &code
when = 'A'
move 1 to #j
break
when = 'B'
when = 'C'
move 2 to #j ! Will happen if &code is B or C.
break
when > 'D'
move 3 to #j ! Move 3 to #j and continue checking.
when > 'H'
add 1 to #j ! Add 1 to #j and continue checking.
when > 'W'
add 2 to #j
break
when-other
if isnull (&code)
do null_code
else
move 0 to #j ! Unknown code.
end-if
break
end-evaluate
See The commands IF and LET
for comparison operators