Trim function in sql server 2017

Before Sql server 2017 we only had LTRIM and RTRIM function available to remove spaces from left and right separately.  With trim function now being available in sql server 2017 it can be used for two purposes.

Lets look at the syntax of Trim function  first.

TRIM ( [ characters FROM ] string )

Trim in sql server 2017 can be used to remove space character or other characters from the start and the end of the string.

Lets now look at the two usage of trim function with example.

  1. It can be used to remove the the space from the left and right side of the string.
  2. It can be used to remove the space and any specified character from left or right of the string.

SELECT TRIM( ‘ sqlag ‘) AS RESULT, ‘First example’
SELECT TRIM( ‘. , #’ FROM ‘ # sqlag . ‘) AS RESULT,’Second example’

 

Trim SQL server 207
Trim in Sql server 2017

 

 

 2,030 total views,  2 views today

Add a Comment

Your email address will not be published. Required fields are marked *