Introduction

In previous versions of SQL Server, we have used the LTRIM () and RTRIM () functions to remove the white spaces from left and right side of the string.

In SQL Server 2017 new function TRIM () introduced which is a combination of LTRIM () and RTRIM () and also used to remove the specific characters from the string.

Explanation

Let’s see the demo of it –

SELECT LTRIM(RTRIM(‘      ABC     ‘));

SELECT TRIM(‘    ABC    ‘);

So, TRIM function in SQL Server 2017 is the single way to remove the spaces from both left and right side of a string.

See Also

https://docs.microsoft.com/en-us/sql/t-sql/functions/trim-transact-sql