THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server RIGHT() Function

❮ SQL Server Functions

Example

Extract a substring from a string (starting from right):

SELECT RIGHT('SQL Tutorial', 3) AS ExtractString;
Try it Yourself »

Definition and Usage

The RIGHT() function extracts a substring from a string (starting from right).

Syntax

RIGHT(string, number_of_chars)

Parameter Values

Parameter Description
string Required. The string to extract from
number_of_chars Required. The number of characters to extract

Note

  • If number_of_chars exceeds the number of characters in string, the RIGHT() function will return string

Technical Details

Works in: SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

More Examples

Example

Extract a substring from the text in a column (starting from right):

SELECT RIGHT(CustomerName, 5) AS ExtractString
FROM Customers;
Try it Yourself »

Example

Extract a substring from a string (starting from right):

SELECT RIGHT('SQL Tutorial', 100) AS ExtractString;
Try it Yourself »

❮ SQL Server Functions