RTRIM (Transact-SQL)
Returns a character string after truncating all trailing blanks.
Compatibility levels can affect return values. For more information, see sp_dbcmptlevel (Transact-SQL).
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.'; GO
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)
RTRIM does not trim CHAR(160)
Important - LTRIM and RTRIM only remove the space character CHAR(32). They do not remove a CHAR(160) which is a non-breaking space . The strings rtrim('12345' + char(160)) and rtrim('12345' + char(32)) are not the same.
- 2/12/2010
- zork2112
