How do I change the case of a string with SQL?

Although rarely, it could happen that you end up with fully capitalized strings in SQL.

Whilst there’s often nothing wrong with the data quality, it’s not very appealing to be showing the users of your analyses data in capital letters. Personally, I always get the feeling of being shouted at when I see fully capitalized strings and that’s the very least tone I’d like my analysis to convey.

So, how do you go about it?

There are two super neat functions that all SQL Server, PostgreSQL and MySQL databases support to this end – lower() and upper().

MySQL has even gone to the lengths of extending lcase() and ucase(), perhaps in an attempt to cater for the habits of both SQL Server and SAP database users

What I miss in every database I’ve worked with so far is a function analogous to proper() in Excel….

It’s not all doom an gloom, though – you could still capitalze each word in your string… But this comes at the expense of qute a bit of coding and thereĀ is no guarantee it would work for strings composed by more than 2 words

Happy SQL-ing!