New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11

IIF

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

The IIF() function checks if the first argument is TRUE to produce the second argument, or the third argument otherwise. It works in a similar way as the NVL2 function or the CASE expression

SELECT
  iif(1 = 1, 3, 4), 
  iif(1 = 2, 3, 4);
create.select(
  iif(inline(1).eq(inline(1)), inline(3), inline(4))
  iif(inline(1).eq(inline(2)), inline(3), inline(4))).fetch();

The result being

+-----+-----+
| iif | iif |
+-----+-----+
|   3 |   4 |
+-----+-----+

Dialect support

This example using jOOQ:

iif(inline(1).eq(inline(2)), inline(3), inline(4))

Translates to the following dialect specific expressions:

-- ACCESS, SQLSERVER
iif(1 = 2, 3, 4)

-- ASE, AURORA_POSTGRES, COCKROACHDB, CUBRID, DB2, DERBY, FIREBIRD, H2, HANA, HSQLDB, INFORMIX, INGRES, ORACLE, POSTGRES, 
-- REDSHIFT, SQLDATAWAREHOUSE, SQLITE, SYBASE, TERADATA, VERTICA
CASE WHEN 1 = 2 THEN 3 ELSE 4 END

-- AURORA_MYSQL, MARIADB, MEMSQL, MYSQL
if(1 = 2, 3, 4)

(These are currently generated with jOOQ 3.15, see #10141)

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo