COALESCE()
- Returns the first non-null expression among its arguments.
SELECT
Name,
Class,
Color,
ProductNumber,
COALESCE(Class, Color, ProductNumber) AS [FirstNotNull]
FROM Production.Product;
SUBSTRING()
- Returns part of a character, binary, text, or image expression.
SELECT SUBSTRING('abcde', 1, 3); -- 'abc'
RIGHT(), LEFT()
RIGHT
Returns the right part of a character string with the specified number of characters.
LEFT
Returns the left part of a character string with the specified number of characters.
SELECT RIGHT('abcde', 3); -- 'cde'
SELECT LEFT('abcde', 3); -- 'abc'
LEN()
- Returns the number of characters of the specified string expression, excluding trailing blanks.
SELECT LEN(N'abcde'); -- 5
DATALENGTH()
- Returns the number of bytes used to represent any expression.
SELECT DATALENGTH(N'abcde'); -- 10
CHARINDEX()
- Searches an expression for another expression and returns its starting position if found.
SELECT CHARINDEX(' ','Itzik Ben-Gan A'); -- 6
PATINDEX()