The TRIM function removes leading and trailing spaces from a string. It is commonly used when cleaning text data imported from external systems.
Unwanted spaces can cause inconsistent comparisons, duplicate-looking values, and data-quality problems.
A department value stored as ' Finance ' can be cleaned using TRIM so that the leading and trailing spaces are removed.
SELECT
TRIM(Department) AS CleanDepartment
FROM Employees;
TRIM is useful when cleaning customer names, addresses, product names, imported CSV data, employee records, and other text fields.
- TRIM removes leading and trailing spaces.
- It is useful for cleaning imported data.
- It can improve text consistency.
- It does not normally remove spaces between words.
- Other functions may be used for more specific whitespace operations.
What does TRIM do?
TRIM removes leading and trailing spaces from a string.
Why is TRIM useful in data analysis?
It helps clean inconsistent text values that contain unwanted spaces.