strright() function

The strright() function returns the rightmost n characters from an input string.

Syntax

The strright() function has the following syntax:
varchar = strright(varchar input, int n);
nvarchar = strright(nvarchar input, int n);

The input value specifies the varchar or nvarchar value from which the characters are returned.

The n value specifies the number of characters to return. If the input value is shorter than the number of characters that are requested, the function returns the entire input string.

Returns

The function returns the rightmost n characters from the input string.

Example

select strright ('1234567891',5);
 STRRIGHT
----------
 67891
(1 row)

select strright ('123',5);
 STRRIGHT
----------
 123
(1 row)