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 entrycontent_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
| Column Name | Type | Description |
|---|---|---|
content_id
PK
|
int | Unique identifier for content |
content_text
|
varchar | Text content to be transformed |
Input & Output
| content_id | content_text |
|---|---|
| 1 | hello world of SQL |
| 2 | the QUICK brown fox |
| 3 | data science AND machine learning |
| 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 |
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.
| content_id | content_text |
|---|---|
| 4 | TOP rated programming BOOKS |
| 5 | advanced sql QUERIES and optimization |
| 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 |
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_idis unique for each row -
content_textcontains only letters and spaces - No special characters or punctuation in the text
-
1 ≤ content_id ≤ 1000