T-SQL 101: 96 Choosing from alternatives with IIF in SQL Server T-SQL
In my last T-SQL 101 post, I described the CASE statement. Until SQL Server 2012, that was the only real option that we had for choosing between alternate values. In SQL Server 2012, Microsoft gave us another option with the IIF function.
The IF function is very similar to the IF function in Microsoft Excel. It takes three parameters:
- A boolean value to check (normally this is an expression)
- A value that will be returned if the first parameter is true.
- A value that will be returned if the first parameter is false.
In the main image above, you can see the equivalent CASE statement and the simplified IF function equivalent.
2021-04-26