RTRIM() Function in SQL Server

The RTRIM() function removes trailing spaces from a string.

Syntax :


Parameter :
RTRIM() function accepts single-parameter like input_string.

  • input_string :
    It is an expression of character or binary data. It can be a literal string, variable, or column.

Returns – It returns a string after truncating all trailing blanks.

Example-1 :
Using RTRIM() function with literal strings.

SELECT RTRIM('GFG a computer science portal for geeks') 
AS RightTrimmedString;

Output :

GFG a computer science portal for geeks

Example-2 :
Using RTRIM() function with a variable.

DECLARE @input_string varchar(25);  
SET @input_string = 'IPL sponsorship this year.';  
SELECT RTRIM(@input_string) + ' Dream11  '; 

Output :

IPL sponsorship this year Dream11

Example-3 :
You can used RTRIM() function with a variable for question and answer as shown in example given below.

DECLARE @input_string varchar(25);  
SET @input_string = 'who is the sponsor for IPL Game this year :';  
SELECT RTRIM(@input_string)+'Dream11' ; 

Output :

who is the sponsor for IPL Game this year :Dream11
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.