Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » String FunctionsRSS Feeds

RIGHT Function

Posted By: Sarita Patel     Category: SQL Server     Views: 2877

This article explains the use of RIGHT function in sql server with examples.

RIGHT function is used to get right part of the specified string with the specified number of characters.  


Syntax of RIGHT Function :

RIGHT ( character_expression ,integer_expression )

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. 

integer_expression is a positive integer that specifies how many characters of the character_expression will be returned. It returns an error if integer_expression is negative.

Return type of RIGHT function is varchar or nvarchar.


Examples of RIGHT Function :

Example 1 : Use of RIGHT function in select clause

SELECT RIGHT('SYNTAX-EXAMPLE',7)  

Output
EXAMPLE

Above example returns rightmost 7 characters of specified string.


Example 2 : Use of RIGHT function to display rightmost 5 characters of table field.

SELECT RIGHT(ShipName,5)  
FROM    Orders

Output
alier
täten
arnes
stock
lices
arnes

Above example displays last 5 characters from field ShipName of orders table.



Example 3 : Use of RIGHT function in where clause

SELECT DISTINCT ShipName
FROM    Orders
WHERE  RIGHT(ShipName,2) = 'on'

Output
ShipName
Eastern Connection
France restauration

Above example displays unique ship name ending with characters 'on' in order table. 
 
  
Share: 

 
 
 

Didn't find what you were looking for? Find more on RIGHT Function Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of RIGHT Function is from United States.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!