Using TRIM, LTRIM, and RTRIM to Clean Text Data
📖 Scenario: You work in a company database where customer names have extra spaces at the start or end due to inconsistent data entry. These spaces cause problems when searching or sorting names.
🎯 Goal: You will create a table with customer names that include extra spaces, then write queries using TRIM, LTRIM, and RTRIM functions to clean the names by removing unwanted spaces.
📋 What You'll Learn
Create a table called
customers with a column name containing names with extra spacesInsert specific customer names with leading and trailing spaces
Write a query using
LTRIM to remove leading spacesWrite a query using
RTRIM to remove trailing spacesWrite a query using
TRIM to remove both leading and trailing spaces💡 Why This Matters
🌍 Real World
Cleaning text data in databases is common when data comes from user input or external sources with inconsistent formatting.
💼 Career
Database administrators and developers often need to clean and standardize text data to ensure accurate queries and reports.
Progress0 / 4 steps