How to Use the RTRIM() Function in SQL Server: A Complete Guide

Rumman Ansari   Software Engineer   2024-07-21 09:33:26   5855  Share
Subject Syllabus DetailsSubject Details
☰ TContent
☰Fullscreen

Table of Content:

Syntax:


RTRIM(Character_Expression)

Removes blanks on the right hand side of the given character expression.

Example: Removing the 3 white spaces on the left hand side of the 'Hello ' string using RTRIM() function.

Code:


Select RTRIM('Hello   ')

Output:

The above code will produce the following result-


Hello

Example: To remove white spaces on either sides of the given character expression, use LTRIM() and RTRIM() as shown below.


Select LTRIM(RTRIM('   Hello   '))

Output:

The above code will produce the following result-


Hello



Stay Ahead of the Curve! Check out these trending topics and sharpen your skills.