The TRIM function removes leading and trailing spaces or specified characters from a string according to the database syntax.
Extra spaces are a common data-quality problem and can cause unexpected results during comparisons and joins.
Remove unwanted spaces from customer names.
SELECT
TRIM(CustomerName) AS CleanCustomerName
FROM Customers;
TRIM is widely used during data cleaning, ETL processes, imports, joins, and text standardization.
- TRIM removes unwanted surrounding spaces.
- It helps clean imported text.
- It can improve comparisons.
- It is useful before joins.
- Database-specific syntax may provide additional options.
What does TRIM do?
TRIM removes leading and trailing spaces or specified characters from text.
Why is TRIM important in data cleaning?
It removes unwanted spaces that can cause duplicate-looking values and failed comparisons.