How to Capitalize the First Letter of Every Word in SQL

To capitalize the first letter of every word in a string in SQL, use the INITCAP() function. This function takes a single argument, which is the string you want to capitalize. For example, if you wanted to capitalize the string hello world, you would use the following query:

SELECT INITCAP('hello world');

Examples

Let's look at a few examples of how this function can be used. Suppose you have a table called names with the following data:

names
name
jane doe
jane doe


If you wanted to capitalize the first letter of each name, you would use the following query:

SELECT INITCAP(name) FROM names;

This query would return the result John Doe and Jane Doe, since the first letter of each name has been capitalized.

Additional Info

The INITCAP() function is supported by most major databases, including MySQL, PostgreSQL, and SQL Server. However, the syntax may vary slightly depending on the database you are using. For more information, check out the documentation for your particular database.

Want to build your own LLM Apps with AirOps👇👇