MS SQL Server RTRIM() Function
Sometime you may need to trim trailing blank space character from your desired text in MS SQL Server. There is a function called RTRIM
in MS SQL Server by which you can do this. RTRIM
function returns a character expression after removing it’s trailing blanks.
Let’s see the function structure:
RTRIM(character_expression)
In this function there is only one parameter. Parameter character_expression
can be character or binary data. character_expression can be a constant, variable, or column. RTRIM
function returns a character expression as VARCHAR or NVARCHAR after removing it’s trailing blanks.
The following example uses RTRIM
to remove trailing spaces from a character variable.
DECLARE @input varchar(60);
SET @input = 'Minhajur Rahman Khan
'; SELECT @input AS 'before_rtrim', LTRIM(@input) AS 'after_rtrim';
Here is the result set.
before_rtrim | after_rtrim |
---|---|
Minhajur Rahman Khan |
Minhajur Rahman Khan |
I have an another post MS SQL Server String Related Functions where you will learn about different string related functions of MS SQL Server.
In this tutorial, I have shown you how to trim trailing blank space character from your desired text in MS SQL Server. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.