IF

Syntax

IF logical_expression

IF commands have the following structure:

IF logical_expression SQR Command... [ELSE SQR Command...] END-IF

Description

Carries out commands depending on the value of a condition.

The expression is evaluated as a logical TRUE or FALSE. A value or expression that evaluates to nonzero is TRUE.

Each IF command must have a matching END-IF command.

IF commands can be nested.

Comparing 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 described in the following list:

  • For DATETIME columns and SQR DATE variables, SQR uses the format specified by the SQR_DB_DATE_FORMAT setting, 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

logical_expression

Any valid logical expression. See the LET command for a description of logical expressions.

Example

The following example illustrates the IF command:

if &price > &old_price and instr(&code, 'M', 1) > 0
   add 1 to #price_count
   if #price_count > 50
      show 'More than 50 prices found.' noline
      input $x 'Continue? (Y/N)'
      if upper($x) = 'N'
         stop
      end-if
   end-if
else
   add 1 to #old_price_count
end-if
if #rows   ! Will be TRUE if #rows is non-zero.
   do print-it
end-if

if $date1 > 'Apr 21 2004 23:59'
   do past_due
end-if

See The LET command for a description of logical expressions

See EVALUATE