From the course: Querying Microsoft SQL Server 2022
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
The IIF logical function - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
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 AdventureWorks. We'll select the BusinessEntityID and SalesYTD columns from the Sales.SalesPerson table. This shows me each employee's ID number and their current sales year-to-date. Let's suppose that 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. 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 right here in these results. To…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
Use functions in T-SQL3m 10s
-
(Locked)
String functions3m 44s
-
(Locked)
Text concatenation3m 40s
-
(Locked)
Round with mathematical functions3m 13s
-
(Locked)
Find the GREATEST or LEAST value5m 5s
-
(Locked)
Work with date functions5m 56s
-
(Locked)
FORMAT date and times3m 36s
-
(Locked)
Group dates into buckets6m 10s
-
(Locked)
Return random records with NEWID2m 22s
-
(Locked)
Create a series of values5m 13s
-
(Locked)
The IIF logical function3m 39s
-
(Locked)
Write a CASE statement4m 34s
-
(Locked)
Challenge: Use functions in a SQL query49s
-
(Locked)
Solution: Use functions in a SQL query13m 55s
-
(Locked)
Solution: Use functions in a query4m 22s
-
-
-
-
-
-