--- description: "RTRIM (Transact-SQL)" title: "RTRIM (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "07/05/2017" ms.prod: sql ms.prod_service: "database-engine, sql-database, synapse-analytics, pdw" ms.reviewer: "" ms.technology: t-sql ms.topic: reference f1_keywords: - "RTRIM_TSQL" - "RTRIM" dev_langs: - "TSQL" helpviewer_keywords: - "RTRIM function" - "character strings [SQL Server], trailing blanks" - "blank characters [SQL Server]" - "trailing blanks" ms.assetid: 52fd6e8d-650c-4f66-abcf-67765aa5aa83 author: LitKnd ms.author: kendralittle monikerRange: ">=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current" --- # RTRIM (Transact-SQL) [!INCLUDE [sql-asdb-asdbmi-asa-pdw](../../includes/applies-to-version/sql-asdb-asdbmi-asa-pdw.md)] Returns a character string after truncating all trailing spaces. ![Topic link icon](../../database-engine/configure-windows/media/topic-link.gif "Topic link icon") [Transact-SQL Syntax Conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md) ## Syntax ```syntaxsql RTRIM ( character_expression ) ``` [!INCLUDE[sql-server-tsql-previous-offline-documentation](../../includes/sql-server-tsql-previous-offline-documentation.md)] ## Arguments *character_expression* Is an [expression](../../t-sql/language-elements/expressions-transact-sql.md) of character data. *character_expression* can be a constant, variable, or column of either character or binary data. *character_expression* must be of a data type that is implicitly convertible to **varchar**. Otherwise, use [CAST](../../t-sql/functions/cast-and-convert-transact-sql.md) to explicitly convert *character_expression*. ## Return Types **varchar** or **nvarchar** ## Examples ### 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. ```sql SELECT RTRIM('Removes trailing spaces. '); ``` [!INCLUDE[ssResult](../../includes/ssresult-md.md)] `Removes trailing spaces.` ### B: Simple Example 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. ```sql SELECT RTRIM('Four spaces are after the period in this sentence. ') + 'Next string.'; ``` [!INCLUDE[ssResult](../../includes/ssresult-md.md)] `Four spaces are after the period in this sentence.Next string.` ### C. Using RTRIM with a variable The following example demonstrates how to use `RTRIM` to remove trailing spaces from a character variable. ```sql 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 ``` [!INCLUDE[ssResult](../../includes/ssresult-md.md)] ``` 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)](../../t-sql/functions/left-transact-sql.md) [LTRIM (Transact-SQL)](../../t-sql/functions/ltrim-transact-sql.md) [RIGHT (Transact-SQL)](../../t-sql/functions/right-transact-sql.md) [STRING_SPLIT (Transact-SQL)](../../t-sql/functions/string-split-transact-sql.md) [SUBSTRING (Transact-SQL)](../../t-sql/functions/substring-transact-sql.md) [TRIM (Transact-SQL)](../../t-sql/functions/trim-transact-sql.md) [CAST and CONVERT (Transact-SQL)](../../t-sql/functions/cast-and-convert-transact-sql.md) [Data Types (Transact-SQL)](../../t-sql/data-types/data-types-transact-sql.md) [String Functions (Transact-SQL)](../../t-sql/functions/string-functions-transact-sql.md)