Open In App

RTRIM() Function in SQL Server

Last Updated : 28 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
The RTRIM() function removes trailing spaces from a string. Syntax :
RTRIM(input_string)
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 :
RightTrimmedString
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

Next Article
Article Tags :

Similar Reads