Using Trim Function in MS SQL

TRIM() function came with MS SQL Server 2017. Previously, we used to handle spaces in the variable with methods such as LTRIM, RTRIM or REPLACE.

With the TRIM() function, we can remove the leading and trailing spaces as well as the characters.

There are 2 different usage patterns. In the first, if only the variable is written inside the TRIM function, it takes the leading and trailing spaces.

SELECT TRIM(' develop ')

the result will be "develop".

The second usage is a little different. The desired characters are written in order and the value to be trimmed is specified using FROM. Typed characters are removed from the beginning and end of the value.

SELECT TRIM('.$_' FROM '$$_develop1..')

the result will be "develop1".



You May Interest

MS SQL Getting List of All Column Names of a Table

Getting List of System Hard Disks with Free Space in MS SQL Serve ...

What Have INCLUDED Columns With SQL Server Indexes ?

What is the Use of DBCC Commands in SQL Server ?

What are the INTERSECT Operators in SQL Server ?