Extract the last 3 characters from a string.
SELECT RIGHT(‘SQL Tutorial’, 3) AS ExtractString; |
The RIGHT() function extracts a specified number of characters from the end of a string.
RIGHT(string, number_of_chars) |
Parameter |
Description |
string |
Required: The string from which to extract. |
Number_of_chars |
Required: The number of characters to extract. If number_of_chars exceeds the string length, it returns the entire string. |
Works in: |
SQL Server (starting from 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse. |
Extract 5 characters from the “CustomerName” column, starting from the right.
SELECT RIGHT(CustomerName, 5) AS ExtractString FROM Customers; |
Extract 100 characters from the end of a string.
SELECT RIGHT(‘SQL Tutorial’, 100) AS ExtractString; |