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

Popular posts from this blog

Decimal number issue from server to client. Wow! Didn't expect this @_@

Shrinking node_modules for AWS Lambda (My First “npm shock” and a Practical Fix)