|
|
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已! |
|
恭喜您是本站第 1729845
位訪客!
登入 | 註冊
|
|
|
|
發表者 |
討論內容 |
冷日 (冷日) |
發表時間:2019/4/17 9:02 |
- Webmaster

- 註冊日: 2008/2/19
- 來自:
- 發表數: 15773
|
- [轉貼]RTRIM (Transact-SQL)
- RTRIM (Transact-SQL)
適用於: 是SQL Server (從 2008 開始) 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲
傳回截斷所有尾端空格的字元字串。
語法
RTRIM ( character_expression )
引數 這是字元資料的運算式。 character_expression 可以是字元或二進位資料的常數、變數或資料行。
character_expression 必須是可以隱含轉換成 varchar 的資料類型。 否則,請使用 CAST 來明確轉換 character_expression。
傳回類型
varchar 或 nvarchar
範例 A. 簡單範例
下列範例會採用在句尾具有空格的字元字串,並且傳回句尾沒有空格的文字。
SELECT RTRIM('Removes trailing spaces. ');
以下為結果集:
B:簡單範例
下列範例會示範如何利用 RTRIM 來移除尾端空格。 這次,有另一個字串串連第一個字串,以顯示空格已消失。
SELECT RTRIM('Four spaces are after the period in this sentence. ') + 'Next string.';
以下為結果集:
Four spaces are after the period in this sentence.Next string.
C. 使用 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
以下為結果集:
SQL
-------------------------------------------------------------------------
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 (Transact-SQL) - SQL Server | Microsoft Docs
|
|
討論串
|