totn SQL Server Functions

SQL Server: RIGHT Function

This SQL Server tutorial explains how to use the RIGHT function in SQL Server (Transact-SQL) with syntax and examples.

Description

In SQL Server (Transact-SQL), the RIGHT function allows you to extract a substring from a string, starting from the right-most character.

Syntax

The syntax for the RIGHT function in SQL Server (Transact-SQL) is:

RIGHT( string, number_of_characters )

Parameters or Arguments

string
The string that you wish to extract from.
number_of_characters
The number of characters that you wish to extract starting from the right-most character.

Note

  • If the number_of_characters exceeds the length of the string, the RIGHT function will return string.

Applies To

The RIGHT function can be used in the following versions of SQL Server (Transact-SQL):

  • SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, SQL Server 2005

Example

Let's look at some SQL Server RIGHT function examples and explore how to use the RIGHT function in SQL Server (Transact-SQL).

For example:

SELECT RIGHT('TechOnTheNet.com', 12);
Result: 'OnTheNet.com'

SELECT RIGHT('TechOnTheNet.com', 4);
Result: '.com'

SELECT RIGHT('Tech On The Net', 8);
Result: ' The Net'

SELECT RIGHT('Tech On The Net', 100);
Result: 'Tech On the Net'