SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-60
IF Statement
IF Statement
Considerations for IF Statement
C Example of IF Statement
An IF statement is a compound statement that provides conditional execution based on
the truth value of a conditional expression.
IF is an SQL/MX extension that you use only in embedded SQL programs in C or
COBOL.
conditional-expression
specifies an SQL conditional expression. The expression can be a relational
expression consisting of relational operators and more than one operand. The
operands are literals or host variables combined with SQL relational operators, <,
>, <=, >=, =, and <>.
The conditional expression can also contain logical operators, such as AND, OR,
and NOT, and predicates but cannot contain column references or subqueries. See
Search Condition on page 6-102.
The conditional expression evaluates to either true, false, or NULL.
SQL-statement;[SQL-statement;]...
is an SQL statement list following the THEN or ELSE keyword. The statements are
executed in sequential order as in compound statement execution; the result of
executing the statement list is exactly the same result as executing the statements
one at a time in sequential order.
NonStop SQL/MX executes an IF statement by evaluating the first (and possibly
only) conditional-expression. If the expression evaluates to true,
NonStop SQL/MX executes the statements following the THEN keyword. If the
expression evaluates to false or NULL, NonStop SQL/MX branches to the first
ELSEIF part of the statement if an ELSEIF exists. Otherwise, with no ELSEIF,
NonStop SQL/MX executes only the ELSE part of the statement, if there is one.
If the conditional-expression of the first ELSEIF evaluates to false or NULL,
NonStop SQL/MX branches to the next ELSEIF part of the statement, and so on. If
all the expressions evaluate to false or NULL, NonStop SQL/MX executes only the
ELSE part of the statement, if there is one.
IF conditional-expression THEN
SQL-statement;[SQL-statement;]...
[ELSEIF conditional-expression THEN
SQL-statement;[SQL-statement;]...]...
[ELSE SQL-statement;[SQL-statement;]...]
END IF
C/COBOL