Querying and aggregation
String functions and collation
Clean text without losing meaning.
Understand the concept
LEN, LEFT, RIGHT, SUBSTRING, REPLACE, TRIM and CONCAT format text. SQL Server LEN excludes trailing spaces; DATALENGTH counts bytes. Unicode character counts and byte counts differ. CONCAT treats NULL inputs like empty strings, which may or may not match the business meaning.
Case and accent comparisons follow collation rules. Wrapping every search column in LOWER can make index access harder; consider the column type and comparison rules. Preserve original values when automatically transforming emails or identifiers.
Use it to inspect imported text and format report output.
Confusing LEN with byte length or silently losing NULL information.
One topic. Three levels of depth.
SELECT FullName, UPPER(FullName) AS DisplayName FROM lab.Customer;The stored name is unchanged; only its presentation changes.
This page does not execute SQL. Practise in the downloadable SqlStudioLab using SSMS. Before rerunning temporary-table examples, remove only the relevant #table. Views, procedures and functions create persistent lab objects; never use a production connection.
Try it yourself first.
Show the first three characters of product names.
Show the solution and explanation
SELECT ProductName, LEFT(ProductName, 3) AS Prefix FROM lab.Product;This is not a reliable classification key; different names can share a prefix.