Click to Rate and Give Feedback
MSDN
MSDN Library
SQL Server
SQL Server 2008
Database Engine
Technical Reference
 RIGHT (Transact-SQL)
Community Content
In this section
Statistics Annotations (0)
Collapse All/Expand All Collapse All
Other versions are also available for the following:
SQL Server 2008 Books Online (October 2009)
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 )
character_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.

integer_expression

Is a positive integer that specifies how many characters of character_expression will be returned. If integer_expression is negative, an error is returned. If integer_expression is type bigint and contains a large value, character_expression must be of a large data type such as varchar(max).

Returns varchar when character_expression is a non-Unicode character data type.

Returns nvarchar when character_expression is a Unicode character data type.

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;
GO
SELECT RIGHT(FirstName, 5) AS 'First Name'
FROM Person.Contact
WHERE ContactID < 5
ORDER BY FirstName;
GO

Here is the result set.

First Name
----------
erine
stavo
berto
Kim

(4 row(s) affected)
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker