Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

RTRIM (Transact-SQL)


Applies To: SQL Server 2014, SQL Server 2016 Preview

Returns a character string after truncating all trailing blanks.

Applies to: SQL Server (SQL Server 2008 through current version), Azure SQL Database, Azure SQL Data Warehouse Public Preview.

Topic link icon Transact-SQL Syntax Conventions

RTRIM ( character_expression )


Is an expression of character data. character_expression can be a constant, variable, or column of either character or binary data.

character_expression must be of a data type that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert character_expression.

varchar or nvarchar

The following example takes a string of characters that has spaces at the end of the sentence, and returns the text without the spaces at the end of the sentence.

SELECT RTRIM('Removes trailing spaces.   ');

Here is the result set.


Removes trailing spaces.

The following example demonstrates how to use RTRIM to remove trailing spaces from a character variable.

DECLARE @string_to_trim varchar(60);
SET @string_to_trim = 'Four spaces are after the period in this sentence.    ';
SELECT @string_to_trim + ' Next string.';
SELECT RTRIM(@string_to_trim) + ' Next string.';

Here is the result set.


Four spaces are after the period in this sentence.     Next string.

(1 row(s) affected)


Four spaces are after the period in this sentence. Next string.

(1 row(s) affected)

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft