IF

<< Click to Display Table of Contents >>

Navigation:  Apollo SQL > Conditional Functions >

IF

Evaluates a Boolean statement, returning one value for True and another for False.

Syntax:

IF(Condition: Boolean, TrueResult, FalseResult): ResultType

 

Condition is a Boolean expression. When the function is evaluated, it returns TrueResult if Condition evaluates to True, else FalseResult. TrueResult and FalseResult need not be of the same type and result type of the IF expression may change depending on Condition.

Example:

SELECT category, suppcode, prodcode, barcode, proddesc, retprice, costprice,

IF(retprice <> 0, (1-costprice*1.125/retprice)*100, 0) as margin FROM hds1

WHERE IF(retprice <> 0, (1-costprice*1.125/retprice), 0) > 0.8) or

(IF(retprice <> 0, (1-costprice*1.125/retprice), 1) < 0.4);