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 - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2019
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
-
-
-
-
-
-
-
(Locked)
Use functions in T-SQL2m 47s
-
(Locked)
String functions3m 24s
-
(Locked)
Text concatenation3m 33s
-
(Locked)
Round with mathematical functions2m 46s
-
(Locked)
Work with date functions4m 53s
-
(Locked)
FORMAT date and times2m 59s
-
(Locked)
Return random records with NEWID2m 2s
-
(Locked)
The IIF logical function3m 9s
-
(Locked)
-
-
-
-
-