Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

RIGHT

Example

Extract the last 3 characters from a string.

SELECT RIGHT(‘SQL Tutorial’3AS ExtractString;

Definition and Usage

The RIGHT() function extracts a specified number of characters from the end of a string.

Syntax

RIGHT(stringnumber_of_chars)

Parameter Values

Parameter

Description

string

Required: The string from which to extract.

Number_of_chars

Required: The number of characters to extract. If number_of_chars exceeds the string length, it returns the entire string.

Technical Details

Works in:

 SQL Server (starting from 2008), Azure SQL Database, Azure SQL Data Warehouse, and Parallel Data Warehouse.

More Examples

Example

Extract 5 characters from the “CustomerName” column, starting from the right.

SELECT RIGHT(CustomerName, 5AS ExtractString
FROM Customers;

Example

Extract 100 characters from the end of a string.

SELECT RIGHT(‘SQL Tutorial’100AS ExtractString;