CASE statement page 4 |
||
Beginning from version 2012, IIF function is available in SQL(Structured Query Language) is a database computer language designed for the retrieval and management of data in relational database management systems (RDBMS), database schema creation and modification, and database object access control management.SQL Server. This function is well known to those who use Access Visual Basic for ApplicationsVBA and is an alternative to the CASE expression in standard SQL. The syntax of IIF function is
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
Using IIF function, we can rewrite the solution of the first task as follows:
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:
If situation will go in the same manner, SWITCH statement could soon appear in T-SQL. :-) |