SQL Server – LTRIM() and RTRIM() Functions

Usage :

The TRIM function in SQL is used to remove specified prefix or suffix from a string.

This is the most common pattern to remove white spaces.

Syntax :

LTRIM(str): Removes all white spaces from the beginning of the string.

RTRIM(str): Removes all white spaces at the end of the string.

Demo 1

SELECT TRIM(‘ Javadotnet ‘);

Result:

‘Javadotnet’

Demo 2

SELECT LTRIM(‘ Javadotnet ‘);

Result:

‘Javadotnet ‘

Demo 3

SELECT RTRIM(‘ Javadotnet ‘);

Result:

‘ Javadotnet’

Categories: SQL

Leave a Reply

Your email address will not be published.