TRIM Unwanted Characters from String in SQL (Quick Tip)
Small thing. Useful thing.
I didn’t know that TRIM in SQL can remove specific characters — not only spaces.
Example
TRIM('.,! ' FROM '# test .')
What It Does
This removes any of the following characters from both sides of the string:
- Dot
. - Comma
, - Exclamation mark
! - Space
The result:
'# test'
Why It’s Useful
- Cleaning imported data
- Sanitizing user input
- Preparing text before comparison
- Normalizing values for indexing
Short. Simple. Powerful.
Comments
Post a Comment