SQL Server : Removes Trailing Spaces from a String

RTRIM() Function

The RTRIM() function is commonly used to remove spaces at the end of string text.

Syntax:

RTRIM(text)

e.g.

DECLARE @String VARCHAR(50) = '   Learn to be happy right now!    '

SELECT RTRIM(@String) TrimmedText



In the example above there are spaces at the beginning and at the end of the text. Because we use RTRIM, the spaces are omitted only at the end (right side)


Also, read the following posts:

Removes Leading and Trailing Spaces from a String (TRIM)

Removes Leading Spaces from a String (LTRIM)

Removes Trailing Spaces from a String (RTRIM)

Post a Comment

0 Comments