Logo 
Search:

SQL Server Articles

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

RTRIM Function

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

This article explains RTRIM function of sql server with examples.

RTRIM function is used to remove trailing spaces from specified string. 


Syntax of RTRIM Function :

RTRIM (character_expression)

character_expression is an expression of character or binary data. character_expression can be a constant, variable, or column.  

Return type of RTRIM function is varchar.


Examples of RTRIM Function :

Example 1 : Use of RTRIM function in select clause

SELECT RTRIM('Syntax-Example   ')  

Output
Syntax-Example

Above example returns removed trailing space string.


Example 2 : Use of RTRIM function to display field value of table.

SELECT LTRIM(ContactName) AS 'Customer Name'    
FROM   Customers

Output
Customer Name
Maria Anders
Ana Trujillo
Antonio Moreno
Thomas Hardy
Christina Berglund
Hanna Moos

Above example displays customer name with removed trailing spaces if any.



Example 3 : Use of RTRIM function in where clause

SELECT ContactName, CompanyName
FROM   Customers
WHERE  RTRIM(ContactName) = RTRIM('ana trujillo  ')

Output
ContactName     CompanyName
Ana Trujillo        Ana Trujillo Emparedados y helados

Above example compares contactname with specified string after removing trailing spaces.
 
  
Share: 

 
 
 

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

Sarita Patel
Sarita Patel author of RTRIM 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!