IIF(< condition>, < expression IF condition IS true>, < expression IF condition ISNOT true>)
The function returns the value of expression in the second parameter, if the condition is evaluated as true, or the value of expression in the third parameter otherwise. So, the function
IIF(condition, expression_1, expression_2)
is equivalent to the following CASE statement:
CASEWHEN condition THEN expression_1 ELSE expression_2 END
Using IIF function, we can rewrite the solution of the first task as follows:
Console
Execute
SELECTDISTINCT product.model,
IIF(price ISNULL, 'Not available', CAST(price AS CHAR(20))) price
In the case where there are more than two variants of branching, you can use nested IIF functions. For example, solution for task 5.10.1 you can get with the following query: