Right( character_expression, integer_expression )
Returns the rightmost ‘integer_expression’ characters from ‘character_expression’.
Example
select Right( 'abcde', 3 )
Differences
The differences in behavior are minimal. In some cases MS SQL Server returns an empty string where ASE returns a NULL
string. In ASE, the NULL string behaves as if it were an empty string. The only real differences are that you cannot use a negative length in MS SQL Server, plus that ASE interprets the empty string as containing one space, so the rightmost character of the empty string is a space.
In the table below, the symbol ∙ represents a space and '' denotes the empty string.
|
|
ASE |
MS SQL Server |
|
Right( a_string, NULL ) |
NULL |
NULL |
x<0 |
Right( a_string, -1 ) |
NULL |
Invalid length |
x≥0 |
Right( NULL, x ) |
NULL |
NULL |
x=0 |
Right( a_string, 0 ) |
NULL |
'' |
x=0 |
Right( '', 0 ) |
NULL |
'' |
x>0 |
Right( '', x ) |
'∙' |
'' |
|
Right( 'abcde', 1 ) |
'e' |
'e' |
|
Right( 'abcde', 7 ) |
'abcde' |
'abcde' |