From the course: Querying Microsoft SQL Server 2019

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

The IIF logical function

The IIF logical function - SQL Server Tutorial

From the course: Querying Microsoft SQL Server 2019

Start my 1-month free trial

The IIF logical function

- [Instructor] The logical function IIF will evaluate a condition and return one value if the condition is true, and a different value if the condition is false. Using this function, you can have SQL Server make decisions about your data for you, or help you place records into groups. To see how this works, I want to take a look at the year-to-date sales history of the employees at Adventure Works. This query shows me the employees' ID number and their current sales year-to-date. Now let's suppose we have a sales goal of $2 million and I'd like to find out which employees have met that target goal and which ones have not. Now you could sort the rows or create a WHERE clause that pulls out just the people with a value over $2 million, but instead, I'd like to create a new column that reveals this information. I'll do this up here in the query on line number three. The IIF logical function can be thought of as an…

Contents