BBampaa

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 →
About 5–10 minutes · no sign-up needed

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

Result:

customer_idformatted_nameformatted_regionformatted_channel
C1001Alice ChenNorth EastOnline
C1002Bob TanakaSouth WestIn-Store
C1003Carol WhiteMidwestOnline
C1004David NguyenWest CoastMobile
C1005Eva MartinezNorth EastIn-Store

Step by step

  1. 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;
  2. 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;
  3. 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

Try each one in your head first, then open the answer.

1. Using customers, write a query to show customer_id with each word's first letter capitalized.
SELECT INITCAP(customer_id) FROM customers
2. Using products, write a query to show brand with each word's first letter capitalized.
SELECT INITCAP(brand) FROM products
3. Using suppliers, write a query to show supplier_name with each word's first letter capitalized.
SELECT INITCAP(supplier_name) FROM suppliers
4. Using employees, write a query to show department with each word's first letter capitalized.
SELECT INITCAP(department) FROM employees
5. Using reviews, write a query to show review_id with each word's first letter capitalized.
SELECT INITCAP(review_id) FROM reviews

Learn 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 →
About 5–10 minutes · no sign-up needed