IF: Testing a Condition

How to:

The IF function tests a condition and returns a value based on whether the condition is true or false.


Top of page

x
Syntax: How to Test a Condition
IF(test, val1, val2)

where:

test

Condition

Is an SQL search condition, which evaluates to true or false.

val1, val2

Are expressions of compatible types.

This function returns a value of the type of val1 and val2. If test is true, val1 is returned, otherwise val2 is returned.



Example: Testing a Condition

This example tests COUNTRY. If the value is ENGLAND, it returns LONDON. Otherwise, it returns PARIS.

IF(COUNTRY = 'ENGLAND', 'LONDON', 'PARIS') = 
   'LONDON'   if COUNTRY is 'ENGLAND'
   'PARIS'    otherwise.

This example tests COUNTRY. If the value is ENGLAND, it returns LONDON. If the value is FRANCE, it returns PARIS. Otherwise, it returns ROME.

IF(COUNTRY = 'ENGLAND', 'LONDON',
   IF(COUNTRY = 'FRANCE', 'PARIS', 'ROME')) = 
   'LONDON'   if COUNTRY is 'ENGLAND'
   'PARIS'    if COUNTRY = 'FRANCE'
   'ROME'     otherwise.

iWay Software