Data types and expressions
Text functions
Build and measure text without changing the source columns.
Lesson 23 of 84
Reading: about 2 min
Lesson + practice: about 12 min
Difficulty: Beginner
On this page4 sections
This lesson uses the unmodified DDI_SQL_Training dataset v1.0.0 on SQL Server 2019 or later. Build and measure text without changing the source columns.
Run the example
sql
SELECT TOP (3) CustomerID,
CONCAT(FirstName, N' ', LastName) AS FullName,
LEN(FirstName) AS NameLength
FROM dbo.Customers
ORDER BY CustomerID;Read it step by step
- CONCAT combines the name parts with an explicit space.
- LEN counts characters in FirstName, excluding trailing spaces.
- ORDER BY CustomerID makes the three-row sample repeatable.
Check the result
| CustomerID | FullName | NameLength |
|---|---|---|
| 1 | Alex Bennett | 4 |
| 2 | Maya Clark | 4 |
| 3 | Leo Evans | 3 |
FullName and NameLength are calculated result columns; the stored names remain separate.
Practice
Show CustomerID and the uppercase City for Customers 1 and 2.
Check your answer and expected result
Reveal answer
sql
SELECT CustomerID, UPPER(City) AS UpperCity
FROM dbo.Customers
WHERE CustomerID IN (1, 2)
ORDER BY CustomerID;| CustomerID | UpperCity |
|---|---|
| 1 | LONDON |
| 2 | MANCHESTER |
The two displayed cities are LONDON and MANCHESTER; City remains unchanged in the table.
Your progress
Reveal the check answer or reach the end to complete this lesson.