茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1729845 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
IMG_60D_00231.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

DB研討會 : [轉貼]去除 MS SQL 欄位中空白

發表者 討論內容
冷日
(冷日)
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 可以是字元或二進位資料的常數、變數或資料行。

character_expression 必須是可以隱含轉換成 varchar 的資料類型。 否則,請使用 CAST 來明確轉換 character_expression。

傳回類型

varchar 或 nvarchar

範例
A. 簡單範例

下列範例會採用在句尾具有空格的字元字串,並且傳回句尾沒有空格的文字。
SELECT RTRIM('Removes trailing spaces.   ');


以下為結果集:
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
前一個主題 | 下一個主題 | | | |

討論串




Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|