The RIGHT function returns a specified number of characters from the end of a string. It is commonly used to extract suffixes and ending portions of identifiers.
Some business identifiers store useful information at the end of a value. RIGHT helps analysts extract that information for reporting and analysis.
An employee code such as 'EMP10025' can use RIGHT to extract the final digits when those digits represent a business identifier.
SELECT
EmployeeCode,
RIGHT(EmployeeCode, 5) AS EmployeeNumber
FROM Employees;
RIGHT is useful for extracting account suffixes, product codes, year values, reference numbers, and other ending characters.
- RIGHT extracts characters from the end of a string.
- The number of characters can be specified.
- It is useful for extracting suffixes.
- It can be combined with other string functions.
- Syntax may vary across database systems.
What does RIGHT do in SQL?
RIGHT returns a specified number of characters from the end of a string.
Why would you use RIGHT?
It can extract useful suffixes or ending portions from structured text values.