Databases Reporting with SQL Working with Text Concatenating Text

Spencer Koss
Spencer Koss
1,170 Points

Capitalizing One Character in a variable from a Database

So lets say we are using this addresses table as an example with the following variables: Street, City, Zip, State, Country

And we wanted to format this exactly the same way our challenge questions asks however with one added caveat.

We want to assume our Database doesn't already have capital letters in the beginning of Street, City, and State.

Question: How would we manipulate those three variables into capitalizing ONLY the first letter in the variable?

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 48,726 Points

You could use substr() and upper() functions to capitalize the first letter. For example with city:

SELECT UPPER(SUBSTR(City,1,1)) || SUBSTR(City,2) AS NewCity FROM addresses;
Spencer Koss
Spencer Koss
1,170 Points

Thank you Kris, do you see much implementation of this in real-world scenarios or is the impact insignificant typically?