Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

RIGHT (Transact-SQL)

Returns the right part of a character string with the specified number of characters.

Topic link icon Transact-SQL Syntax Conventions

RIGHT ( character_expression , integer_expression )


Is an expression of character or binary data. character_expression can be a constant, variable, or column. character_expression can be of any data type, except text or ntext, that can be implicitly converted to varchar or nvarchar. Otherwise, use the CAST function to explicitly convert character_expression.


Is a positive integer that specifies how many characters of the character_expression will be returned. If integer_expression is negative, an error is returned. integer_expression can be of type bigint.

varchar or nvarchar

Compatibility levels can affect return values. For more information, see sp_dbcmptlevel (Transact-SQL).

The following example returns the five rightmost characters of the first name for each contact.

USE AdventureWorks;
SELECT RIGHT(FirstName, 5) AS 'First Name'
FROM Person.Contact
WHERE ContactID < 5
ORDER BY FirstName;

Here is the result set.

First Name

(4 row(s) affected)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft