Transact-SQL Reference

RIGHT

Returns the part of a character string starting a specified number of integer_expression characters from the right.

Syntax

RIGHT ( character_expression , integer_expression )

Arguments

character_expression

Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data.

integer_expression

Is the starting position, expressed as a positive whole number. If integer_expression is negative, an error is returned.

Return Types

varchar

character_expression must be of a data type that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert character_expression.

Remarks

Compatibility levels can affect return values. For more information, see sp_dbcmptlevel.

Examples

This example returns the five rightmost characters of each author's first name.

USE pubs
GO
SELECT RIGHT(au_fname, 5) 
FROM authors
ORDER BY au_fname
GO

Here is the result set:

------------------
raham 
Akiko 
lbert 
Ann   
Anne  
Burt  
rlene 
heryl 
Dean  
Dirk  
ather 
Innes 
hnson 
Livia 
jorie 
ander 
chael 
ichel 
gstar 
inald 
heryl 
earns 
ylvia 
(23 row(s) affected)

See Also

CAST and CONVERT

Data Types

String Functions