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)