First Letter Capitalization - Problem

You have a user_content table containing text content that needs to be formatted with proper capitalization.

Table Structure:

  • content_id: Unique identifier for each content entry
  • content_text: The text content to be transformed

Task: Transform the text by capitalizing the first letter of each word while converting all other letters to lowercase. Preserve all existing spaces between words.

Return: A result table with both the original text and the converted text where each word starts with a capital letter.

Table Schema

user_content
Column Name Type Description
content_id PK int Unique identifier for content
content_text varchar Text content to be transformed
Primary Key: content_id
Note: Each row contains unique content that needs title case formatting

Input & Output

Example 1 — Basic Text Transformation
Input Table:
content_id content_text
1 hello world of SQL
2 the QUICK brown fox
3 data science AND machine learning
Output:
content_id original_text converted_text
1 hello world of SQL Hello World Of Sql
2 the QUICK brown fox The Quick Brown Fox
3 data science AND machine learning Data Science And Machine Learning
💡 Note:

Each word's first letter is capitalized while all other letters become lowercase. The function handles mixed case input like 'QUICK' and 'AND' by converting them to proper title case.

Example 2 — All Caps and Mixed Content
Input Table:
content_id content_text
4 TOP rated programming BOOKS
5 advanced sql QUERIES and optimization
Output:
content_id original_text converted_text
4 TOP rated programming BOOKS Top Rated Programming Books
5 advanced sql QUERIES and optimization Advanced Sql Queries And Optimization
💡 Note:

Words in all caps like 'TOP' and 'BOOKS' are converted to title case. The INITCAP function preserves spacing and handles any combination of uppercase and lowercase letters.

Constraints

  • content_id is unique for each row
  • content_text contains only letters and spaces
  • No special characters or punctuation in the text
  • 1 ≤ content_id ≤ 1000

Visualization

Tap to expand
First Letter Capitalization INPUT content_text (column) Sample Data: "hello WORLD" "jOHN DOE" "PYTHON programming" Text with mixed case letters in each word ALGORITHM STEPS 1 Split Text Separate into words 2 Lowercase All Convert to lowercase 3 Capitalize First Uppercase first letter 4 Join Words Concatenate result "hello WORLD" --> "Hello World" INITCAP(content_text) or title() function FINAL RESULT Original --> Converted "hello WORLD" "Hello World" "jOHN DOE" "John Doe" "PYTHON programming" "Python Programming" OK - Formatted Both original and converted returned in result set Key Insight: The INITCAP() function (SQL) or title() method (Python) handles the transformation in one step. It automatically lowercases all letters first, then capitalizes the first letter of each word. TutorialsPoint - First Letter Capitalization | Optimal Solution
Asked in
Amazon 23 Microsoft 18 Google 15
23.4K Views
Medium Frequency
~8 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen