IIF
Evaluates a boolean expression and returns one of two values accordingly.
This function corresponds to the iif(X, Y, Z) function in SQLite. It evaluates the boolean expression (X). If the expression is true (non-zero), it returns the value of trueValue (Y). If the expression is false (zero), it returns the value of falseValue (Z).
Note: If the expression evaluates to NULL, the result will also be the falseValue.
The return type of the IIF function is determined by the types of trueValue and falseValue. KQLite currently resolves this to a String column, but the underlying data type in SQLite will have the "best" affinity based on the two possible return values.
Example
// Categorize products based on price
// SELECT iif(price > 100, 'Expensive', 'Affordable') FROM Products
val category = select(IIF(Products.price gt 100, StringLiteral("Expensive"), StringLiteral("Affordable")))
.from(Products)
// Provide a gender-specific title
// SELECT 'Hello ' || iif(gender = 'M', 'Mr.', 'Ms.') || ' ' || lastName FROM Users
val greeting = select(StringLiteral("Hello ") CONCAT IIF(Users.gender eq "M", StringLiteral("Mr."), StringLiteral("Ms.")) CONCAT " " CONCAT Users.lastName)
.from(Users)Return
A KQLiteColumn of the appropriate type to represent the result of the IIF operation.
Author
MOHAMMAD AZIM ANSARI
Parameters
A column or expression that evaluates to a boolean (true or false).
The column or value to return if the expression is true.
The column or value to return if the expression is false.