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.