SQL Server INLINE IF ELSE

I understand that this question (which shows up at the top of google results for “sql server inline if”) is 2 years old, but with SQL Server 2012, the answers are somewhat outdated. It also appears to be a duplicate of SQL inline if statement type question, but that question (being an even older one), doesn’t have an up to date answer either.

In SQL Server 2012 you can use the IIF function:

IIF ( boolean_expression, true_value, false_value )

Example:

SELECT IIF(someColumn = 1, 'yes', 'no')

Leave a Comment