And we are using the IIF function in the WHERE clause to handle the condition when the specified gender is NULL. WHERE gender = is NULL,'Male', the example, we have created a stored procedure to filter out records based on gender. Let’s understand this implementation of using the IIF() in the WHERE clause of a store with the help of an example. The IIF() function also be used to evaluate a condition in the WHERE clause within a stored procedure. IIF(condition, value_if_true, value_if_false) The IIF() is a function in SQL Server that evaluates a condition and returns a value based upon the factor of whether the condition is TRUE or FALSE. Here is the simple execution of the above procedure. And we are using the CASE statement in the WHERE clause to handle the condition when the specified gender is NULL. In the above example, we have created a stored procedure to filter out records based on gender. Now for better understanding, consider the following example given below.
![sql server case statement sql server case statement](https://www.tech-recipes.com/wp-content/uploads/2019/05/How-To-USE-IF...ELSE-In-SQL-Server-1.jpg)
WHEN Boolean_expression THEN result_expression Here is a standard syntax of the Case statement that we can use with the WHERE clause in a stored procedure.
![sql server case statement sql server case statement](http://i.stack.imgur.com/DskEb.png)
Moreover, any statement or clause that permits a valid expression can use CASE.ĬASE can be used in SELECT, UPDATE, DELETE, and SET statements, as well as clauses like select list, IN, WHERE, ORDER BY, and HAVING. The Case statement in SQL Server returns one of several possible result expressions after evaluating a list of conditions.
![sql server case statement sql server case statement](https://i.ytimg.com/vi/UWc5-wWc2fg/maxresdefault.jpg)
And we will also discuss them with examples. But don’t worry, there are still some alternatives available in SQL Server that we can use instead of IF-ELSE.