RTRIM Function in MS SQL Server and MySQL


RTRIM stands for right trim — it trims blank spaces occurring on the right side of a given string.

MSSQL

Syntax:

RTRIM(string)

Example:

select RTRIM('smith    ');
------------------------
smith

select RTRIM('Hello');
-------------------
Hello

RTRIM Function Example 1

select 'Smith '+' David' as Normal_String, RTRIM('Smith ')+' David' as [truncated string]
Normal_String       truncated string
-------------       ----------------
Smith   David       Smith David

RTRIM function example in MSSQL

MySQL

In MySQL, RTRIM does the same job — it trims any blank spaces from the right side of a given string.

Syntax:

RTRIM(string)

Example:

mysql> select RTRIM('smith  ');
+-------------------+
| RTRIM('smith  ')  |
+-------------------+
| smith             |
+-------------------+

mysql> select RTRIM('Hello');
+----------------+
| RTRIM('Hello') |
+----------------+
| Hello          |
+----------------+

RTRIM function in MySQL

Back to Converting Functions from MSSQL to MySQL