TRIM()–New String function in SQL Server 2017

SQL Server 2017 introduces long awaited string function which supports both LTRIM() and RTRIM() together

Syntax for the function is as follows

TRIM ( [ characters FROM ] string )

Example usage

SELECT TRIM(‘   SQLXpertise   ‘) [SQL2017]



In addition to trimming spaces, TRIM() function supports removing other characters in prefix and suffix as well, see below example, we are providing #, ~, <SPACE> as characters to removed from Prefix and Suffix

Example with Character removal

SELECT TRIM(‘#~ ‘ FROM ‘#   SQLXpertise   ~’) [SQL2017]




This new function will be helpful in using one TRIM() call rather than 3 function calls of LTRIM(), RTRIM() and REPLACE()

Hope  you find this post helpful !!!


Author: Arunraj

I am a Microsoft Certified Technology Specialist (Database Developer). I work on SQL Server programming since SQL Server 7.0 specializes in SQL Server Programming and Performance Tuning and has 14 years of hands-on experience. I hold a Master Degree in Computer Applications. I am also part of NJSQL User Group and Northern New Jersey .Net User Group.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: