Quick Reference
The SQL Server TRIM() function removes leading and trailing spaces (default) OR other specified characters from the start or end of a string.
The following removes the leading and trailing spaces from the string.
SELECT TRIM(' 1SMARTchicken! ') AS Trimmed;
The following removes ‘1’, ‘!’, and spaces from the beginning and end of the string.
SELECT TRIM('1! ' FROM ' 1SMARTchicken! ') AS Trimmed;
Output – Example 1
Trimmed
1SMARTchicken!
Output – Example 2
Trimmed
SMARTchicken
Syntax
TRIM([characters FROM ]string)
Parameters
Parameter | Description |
---|---|
characters FROM | Specific characters to remove (optional) |
string | The string to remove spaces or characters from (required) |
SQL Notes:
- Any work being done to modify the structure of a database or delete tables or the the database itself should only be done after making a recent backup
We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.