RTRIM (Transact-SQL)RTRIM (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
末尾のスペースを切り捨てた後の文字列を返します。Returns a character string after truncating all trailing spaces.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
RTRIM ( character_expression )
注意
SQL Server 2014 以前の Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
引数Arguments
character_expressioncharacter_expression
文字データの式です。Is an expression of character data. character_expression には、文字データまたはバイナリ データの定数、変数、または列を使用できます。character_expression can be a constant, variable, or column of either character or binary data.
character_expression に暗黙的に変換できるデータ型である必要があります varchar です。character_expression must be of a data type that is implicitly convertible to varchar. それ以外の場合は、CAST を指定して明示的に character_expression を変換します。Otherwise, use CAST to explicitly convert character_expression.
戻り値の型Return Types
varchar または nvarcharvarchar or nvarchar
例Examples
A.A. 簡単な例Simple Example
次の例では、文末に空白のある文字列を受け取り、文末の空白を除くテキストが返されます。The following example takes a string of characters that has spaces at the end of the sentence, and returns the text without the spaces at the end of the sentence.
SELECT RTRIM('Removes trailing spaces. ');
結果セットは次のようになります。Here is the result set.
Removes trailing spaces.
B: 簡単な例B: Simple Example
この例では、RTRIM
を使用して末尾のスペースを削除します。The following example demonstrates how to use RTRIM
to remove trailing spaces. 今回は、スペースがなくなったことを示すために、最初の文字列に連結された別の文字列があります。This time there is another string concatenated to the first string to show that the spaces are gone.
SELECT RTRIM('Four spaces are after the period in this sentence. ') + 'Next string.';
結果セットは次のようになります。Here is the result set.
Four spaces are after the period in this sentence.Next string.
C.C. RTRIM を変数付きで使用するUsing RTRIM with a variable
この例では、RTRIM
を使用して文字変数から後続する空白を削除します。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.
Four spaces are after the period in this sentence. Next string.
参照See Also
LEFT (Transact-SQL)LEFT (Transact-SQL)
LTRIM (Transact-SQL)LTRIM (Transact-SQL)
RIGHT (Transact-SQL)RIGHT (Transact-SQL)
STRING_SPLIT (Transact-SQL)STRING_SPLIT (Transact-SQL)
SUBSTRING (Transact-SQL)SUBSTRING (Transact-SQL)
TRIM (Transact-SQL)TRIM (Transact-SQL)
CAST および CONVERT (Transact-SQL) CAST and CONVERT (Transact-SQL)
データ型 (Transact-SQL) Data Types (Transact-SQL)
文字列関数 (Transact-SQL)String Functions (Transact-SQL)