RTRIM (Transact-SQL)
截断所有尾随空格后返回一个字符串。
语法
RTRIM ( character_expression )
参数
返回类型
varchar 或nvarchar
示例
A. 简单示例
以下示例将接受一个在句子结尾包含空格的字符串,并返回在句子结尾没有空格的文本。
SELECT RTRIM('Removes trailing spaces. ');
下面是结果集:
-------------------------------------------------------------------------
Removes trailing spaces.
B. 将 RTRIM 用于变量
以下示例显示如何使用 RTRIM 删除字符变量中的尾随空格。
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
下面是结果集:
-------------------------------------------------------------------------
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)