SQL Server Interview Question #59
What are common string functions in SQL Server?
SELECT, Filtering, Sorting & Built-in Functions Mid-Level Intermediate
Detailed Explanation
Frequently used string functions include LEN, DATALENGTH, UPPER, LOWER, LTRIM, RTRIM, TRIM, LEFT, RIGHT, SUBSTRING, REPLACE, CHARINDEX, CONCAT, STRING_AGG, and others.
LEN returns the number of characters excluding trailing spaces, while DATALENGTH returns the number of bytes used by the expression. Knowing that distinction is useful in troubleshooting storage and string-length issues.
Code Example
SELECT Name,
LEN(Name) AS CharacterLength,
UPPER(Name) AS UpperName,
LEFT(Name, 10) AS ShortName
FROM dbo.Products;