How to remove right space from a string

To remove the right space from a string uses sql RTRIM function. The RTRIM function delete spaces from the right of the string.

Syntax

RTRIM ( character_expression )


Example

SELECT RTRIM('Hello    ') AS Result;

Result
Hello

Example

DECLARE @var_string varchar(100);
SET @var_string = 'Remove the right space.     ';
SELECT RTRIM(@var_string);
GO

Result
Remove the right space