RIGHT()
Returns the right part of a character string with the specified number of characters.
Signature
RIGHT ( character_expression , integer_expression )Parameters
- 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 *character_expression* will be returned. If *integer_expression* is negative, an error is returned. If *integer_expression* is type bigint and contains a large value, *character_expression* must be of a large data type such as varchar(max).
Examples
SELECT RIGHT('keyboard', 5) AS last_five;last_five
---------
boardSELECT RIGHT('abcdefg', 2);fgRun against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.
Available on
- SQL Server 2017 and later
- Azure SQL Database
- Azure SQL Managed Instance
- Azure Synapse Analytics
- Analytics Platform System (PDW)
- Microsoft Fabric warehouse
- Fabric SQL database
Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.