T-SQL Tutorial

T-SQL Right function


Right Example 1:

SELECT RIGHT ('zxcvbnm',3);
Result: bnm

SELECT RIGHT ('12345',2);
Result: 45

SELECT RIGHT (78901,2);
Result: 01

SELECT RIGHT ('1a2b3c',4);
Result: 2b3c

Right Example 2:

Cities table:

CITY_IDNAMESTATE
1New YorkNew York
2Los AngelesCalifornia
3ChicagoIllinois
4San AntonioTexas
5San DiegoCalifornia

SELECT RIGHT (name, 4) AS Result
FROM cities WHERE city_id=1;

Right Result:

Result
York

See also: T-SQL Functions -> Substring | Right | Rtrim | Upper | Left | LTRIM