February 1, 2018
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.
- It can be used to remove the the space from the left and right side of the string.
- 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’
2,030 total views, 2 views today