IIF Function was introduced with SQL Server 2012. This function returns one of two values depends on the conditions.
Syntax: IIF ( boolean_expression, true_value, false_value )
Example:
Declare @First int = 10 Declare @Second int = 15 Select IIF(@First > @Second, 'True', 'False')
Result: False
IIF with NULL parameters
Declare @First int = null Declare @Second int = null Select IIF(@First > @Second, 'True', 'False')
Result: False
IIF with NULL constants
Declare @First int = 10 Declare @Second int = 15 Select IIF(@First > @Second, null, null)
Result: At least one of the result expressions in a CASE specification must be an expression other than the NULL constant.