Tutorialsteacher

Follow Us

Articles
  • C#
  • C# OOP
  • ASP.NET Core
  • ASP.NET MVC
  • LINQ
  • Inversion of Control (IoC)
  • Web API
  • JavaScript
  • TypeScript
  • jQuery
  • Angular 11
  • Node.js
  • D3.js
  • Sass
  • Python
  • Go lang
  • HTTPS (SSL)
  • Regex
  • SQL
  • SQL Server
  • PostgreSQL
  • MongoDB
  • SQL Server - Get Started
  • Install SQL Server
  • SQL Server Management Studio
  • SQL Server - Windows Authentication
  • SQL Server - Authentication
  • SQL Server - Create New User
  • SQL Server - GRANT/REVOKE Permissions to User
  • SQL Server - Data Types
  • SQL Server - Naming Conventions
  • SQL Server - CREATE Database
  • SQL Server - CREATE Table
  • Add Columns
  • Identity Column
  • Rename Column, Table
  • Drop Columns
  • SQL Server - Schema
  • SQL Server - Tables Relations
  • SQL Server - Primary Keys
  • Modify/Delete Primary Keys
  • SQL Server - Foreign Keys
  • Modify/Delete Foreign Keys
  • SQL Server - Check Constraints
  • SQL Server - Unique Constraints
  • SQL Server - Views
  • Modify/Delete Views
  • SQL Server - Functions
  • SQL Server - Stored Procedures
  • Stored Procedure Parameters
  • SQL Server - Indexes
  • Non-clustered Indexes
  • Modify/Delete Indexes
  • SQL Server - Triggers
  • DDL Triggers
  • LOGON Triggers
  • Enable/Disable Triggers
  • Modify/Delete Triggers
  • SQL Server - Sequence
  • SQL Server - Synonyms
  • SQL Server - IF ELSE Statement
  • SQL Server - Loops
  • SQL Server - Insert Data
  • SQL Server - Update Data
  • SQL Server - Delete Data
  • SQL Server - Select Query
  • WHERE Clause
  • GROUP BY Clause
  • HAVING Clause
  • ORDER BY Clause
  • SQL Server - Inner Join
  • Left Join
  • Right Join
  • Full Join
  • Self Join
  • Dynamic SQL
  • Built-in Functions
Entity Framework Extensions - Boost EF Core 9
  Bulk Insert
  Bulk Delete
  Bulk Update
  Bulk Merge

SQL Server RTRIM() Function: Removes Trailing Spaces

In SQL Server, the RTRIM() function removes all the trailing spaces from right side in the specified string and returns a new string.

RTRIM(input_string)

Parameters

input_string: A string that can be a constant, variable, or a table column. It must be of a data type that can be implicitly convertible to varchar data type else use CAST to explicitly convert.

Return Value

Returns a string without trailing space of varchar or nvarchar type.

Example 1:

In the following example, the RTRIM() is used to trim the trailing spaces in a string, as shown below.

Example: RTRIM()
SELECT RTRIM('Have a nice day!         ')

Example 2:

In the following example, the input string has leading and trailing blanks. the RTRIM() function truncates the trailing blanks and the blanks at the beginning of the string are not truncated.

Example: RTRIM()
SELECT RTRIM('    Have a nice day!         ') AS Greetings;

Use the LTRIM() and RTRIM() functions together to truncate leading and trailing blanks from the string, as shown below.

Example: RTRIM()
SELECT LTRIM(RTRIM('   Have a nice day!         ')) AS Greetings;

Example 3:

The following example shows a string having trailing blanks joined with another string. The result shows the RTRIM() function removes the trailing spaces from the first string.

Example: RTRIM() RTRIM()
SELECT RTRIM('Have a nice day!       ') + ' Goodbye' AS Greetings;

Example 4:

In the following SQL statement, the RTRIM() function is used to trim all trailing blanks from the Email column of the Employee table.

Example: RTRIM()
Update Employee
SET EMail = RTRIM(EMail)
TUTORIALSTEACHER.COM

TutorialsTeacher.com is your authoritative source for comprehensive technologies tutorials, tailored to guide you through mastering various web and other technologies through a step-by-step approach.

Our content helps you to learn technologies easily and quickly for learners of all levels. By accessing this platform, you acknowledge that you have reviewed and consented to abide by our Terms of Use and Privacy Policy, designed to safeguard your experience and privacy rights.

contact@tutorialsteacher.com

ABOUT USTERMS OF USEPRIVACY POLICY
copywrite-symbol

2024 TutorialsTeacher.com. (v 1.2) All Rights Reserved.