Export (0) Print
Expand All
ABS
ALL
AND
ANY
AVG
bit
COS
COT
DAY
EXP
GO
IN
LEN
LOG
MAX
MIN
NOT
OR
PI
SET
SIN
STR
SUM
TAN
USE
VAR
Expand Minimize

RIGHT

SQL Server 2000

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

Syntax

RIGHT ( character_expression , integer_expression )

Arguments

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 the character_expression will be returned. If integer_expression is negative, an error is returned.

Return Types

varchar or nvarchar

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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft