IF Expressions

IF expressions are conditions that can are used in an expression or are expressions.

You can use the IF-THEN-ELSE subexpression in an expression or as an expression by itself. The IF-THEN-ELSE expression uses the following syntax:

IF 
condition 
THEN 
expression 
[ELSE 
expression
] 
END [IF] 

Note that the ELSE expression is optional. If none of the conditions of an IF-THEN-ELSE expression are met and no ELSE subexpression is specified, the output is NULL.

CCL also supports the following IF-THEN-ELSEIF-THEN syntax:

IF 
condition 
THEN 
expression 
ELSEIF 
condition 
THEN 
expression 
[ELSEIF...THEN...] 
[...] 
END [IF] 

The effect of the IF-THEN-ELSEIF-THEN expression is similar to the CASE expression. Here is an example:

SELECT (IF Price<1000 THEN 1
  ELSEIF Price >= 1000 AND Price <1500 THEN 1.5
  ELSE 2
  END) 

Specify the ELSEIF condition as one word. Sybase CEP Engine interprets the condition ELSEIF as an ELSE condition with a nested IF condition.