Lessons › SQL › Deep Dive: Text, Date & Number Functions
SQL lesson
INITCAP() or equivalent
INITCAP capitalizes the first letter of every word and lowercases the rest, turning whatever casing chaos came in into clean, consistent title case.
Try this lesson free →Example
Cleaning Retail Name Casing with INITCAP()
SELECT customer_id, INITCAP(full_name) AS formatted_name, INITCAP(region) AS formatted_region, INITCAP(channel) AS formatted_channel
FROM customers| customer_id | formatted_name | formatted_region | formatted_channel |
|---|---|---|---|
| C1001 | Alice Chen | North East | Online |
| C1002 | Bob Tanaka | South West | In-Store |
| C1003 | Carol White | Midwest | Online |
| C1004 | David Nguyen | West Coast | Mobile |
| C1005 | Eva Martinez | North East | In-Store |
Step by step
- Run the query without INITCAP so you can see what the unfiltered values look like.
SELECT customer_id, full_name, INITCAP(region) AS formatted_region, INITCAP(channel) AS formatted_channel FROM customers; - INITCAP capitalizes the first letter of each word.
SELECT customer_id, INITCAP(full_name), INITCAP(region) AS formatted_region, INITCAP(channel) AS formatted_channel FROM customers; - AS gives the INITCAP result a friendly column name so the output reads cleanly.
SELECT customer_id, INITCAP(full_name) AS formatted_name, INITCAP(region) AS formatted_region, INITCAP(channel) AS formatted_channel FROM customers;
Practice
1. Using customers, write a query to show customer_id with each word's first letter capitalized.
SELECT INITCAP(customer_id) FROM customers2. Using products, write a query to show brand with each word's first letter capitalized.
SELECT INITCAP(brand) FROM products3. Using suppliers, write a query to show supplier_name with each word's first letter capitalized.
SELECT INITCAP(supplier_name) FROM suppliers4. Using employees, write a query to show department with each word's first letter capitalized.
SELECT INITCAP(department) FROM employees5. Using reviews, write a query to show review_id with each word's first letter capitalized.
SELECT INITCAP(review_id) FROM reviewsLearn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →