Trimming removes spaces or specified characters from both the beginning and end of a string.
SELECT TRIM(‘ SQL Tutorial! ‘) AS TrimmedString; |
The TRIM() function removes either space characters or specified characters from both the beginning and end of a string.
By default, it removes leading and trailing spaces.
Note: Consider using LTRIM() to remove leading spaces and RTRIM() to remove trailing spaces specifically.
TRIM([characters FROM ]string) |
Parameter |
Description |
Characters FROM |
Optional. Specify specific characters to remove from the string. |
string |
Required. The string from which spaces or characters should be removed. |
Works in: |
Available in SQL Server from 2017 onward and in Azure SQL Database. |
Remove specified characters and spaces from a string.
SELECT TRIM(‘#! ‘ FROM ‘ #SQL Tutorial! ‘) AS TrimmedString; |