RTRIM()
The RTRIM Transact-SQL function returns a character string after truncating all trailing spaces.
Signature
RTRIM ( character_expression )Parameters
- character_expression — An expression of character or binary data. *character_expression* can be a constant, variable, or column. *character_expression* must be of a data type, except text, ntext, and image, that is implicitly convertible to varchar. Otherwise, use CAST to explicitly convert *character_expression*.
- characters — Applies to: SQL Server 2022 and later.
Examples
SELECT '[' + RTRIM('keyboard ') + ']' AS trimmed;trimmed
-------------
[keyboard]SELECT RTRIM('Removes trailing spaces. ');Removes trailing spaces.SELECT RTRIM('.123abc.' , 'abc.');.123Run against SQL Server 16.0.4265.3 on 2026-09-13. This is the output we got, not the documentation’s.
Available on
- SQL Server 2017 and later
- SQL Server 2019 and later
- SQL Server 2022 and later
- Azure SQL Database
- Azure SQL Managed Instance
- Azure Synapse Analytics
- Analytics Platform System (PDW)
- Microsoft Fabric warehouse
- Fabric SQL database
Signature and description adapted from the Microsoft SQL documentation, used under the CC BY 4.0. SQL Server and Azure are trademarks of the Microsoft group of companies. This page is not affiliated with Microsoft.