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.
Find the GREATEST or LEAST value - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
Find the GREATEST or LEAST value
- [Instructor] There are two new functions that have been added to SQL Server 2022 that'll help you compare numbers and text strings across multiple columns in the same row, they're called greatest and least. Let's see how they work by selecting all of the first and last names of all of the people in the person's table. I'll also sort these names by the business entity ID so that they're not in an alphabetical order in the results. Let me execute the query so we can see the raw data that we're about to work with. Okay, now we can compare each person's first name to their last name and find out which one comes first alphabetically. To do that, we'll use the new greatest function. The greatest function takes multiple arguments and these are the columns that hold the values that you want to compare. In our case, I'm going to compare the first name values to the last name values. I'll name the results of this greatest…
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
-
-
-
-
-
-