SQL RIGHT() Function


The SQL RIGHT() is a function, and extracts substring or number of characters from a given input string or text.

The SQL RIGHT() function is extracts data or substring from RIGHT most character.

The SQL RIGHT() function is supports or work with character and numeric based columns.

It can be used in any valid SQL SELECT statement as well in SQL where clause.

You can also search these topics using sql right function, sql server right function, sql server right string, right function sql, sql right command.

SQL RIGHT() Syntax

The below syntax is used to extracts substring or number of characters from a given input string or text.


SELECT RIGHT(string or text, number_of_characters);

The below syntax is used to extracts substring or number of characters from a given table column or field.


SELECT RIGHT(column_name1, number_of_characters) FROM table_name;


SQL RIGHT() Example - Using Expression Or Formula

The following SQL SELECT statement will extract number of characters of a given input string or text.


SELECT RIGHT('I am fine', 7) AS 'Read 7 chars from right side';

The result of above query is:

Read 7 chars from right side
am fine

SQL RIGHT() More Example

Input Value Result
RIGHT('Hi ... Hello', 2) lo
RIGHT('it's nice database tutorial!', 13) base tutorial!
RIGHT('12345', 3) 543

Sample Database Table - Books

BookId BookName BookPrice RelYear DomainName AuthorName
1 Professional Microsoft SQL Server 140 2010 Security Keshavan
2 Beginning SQL Queries 75 2015 Programming Harish Karthik
3 MySql Concurrency 199.97 2014 Administration Vinoth Kumar
4 From Access To SQL Server 100 2015 Administration Vidyavathi

SQL RIGHT() Example - With Table Column

The following SQL statement selects the "BookID", "BookName" and "RelYear" fields from the "Books" table, and extract the specified number of characters from "Books" table:


SELECT BookID,
RIGHT(BookName, 6) As 'Book Name Last 6 Char(s)',
RIGHT(RelYear, 2) As 'Release Year Last 2 Char(s)' 
FROM Books;

The result of above query is:

BookID Book Name Last 6 Char(s) Release Year Last 2 Char(s)
1 Server 10
2 ueries 15
3 rrency 14
4 Server 15
You can also search these topics using sql select right characters, sql right of character, right function in sql, sql string functions with examples, sql query string functions, sql string functions examples, string functions in sql server, sql select substring.