Converting T-SQL strings to Proper Case, Camel Case, Snake Case, or Kebab Case

Often when I'm moving data around (usually with SSIS but also with just T-SQL), I need to take text that is all capitalized or simply has messed-up capitalization, and convert it to something that looks better (and more human readable) in the target system.

The most common option for me is conversion to Proper Case. Here's an example. Let's start with the following text:




On a webpage or report, that's going to look downright ugly. In the March 2017 update to SDU_Tools, we added functions to do all of the above. SDU Tools is a free library for SQL Server developers and DBAs. You can easily just add it to your database, then call the functions as needed. The functions get added in a separate schema and are easy to remove later if you ever wish to. (We hope you won't want to). They're also easy to upgrade.

Let's look at the output from the function:


The function has been built to allow for common capitalization rules in names and addresses. Here's another example:



While Proper Case is useful, it's not always what's needed. Let's look at the difference with a book title:


The key difference with Title Case is that minor words like "for", "and", "to", etc. aren't capitalized.

While we were adding these functions, we also decided to add a few other common ones. Snake case and Kebab Case look like this:



Note that in Snake Case, the words are all lower-cased and any whitespace between the words is replaced by a single underscore.

In Kebab Case, every word is capitalized and dashes (hyphens) are inserted between the words.

You can find out more about our free SDU Tools here:

One thought on “Converting T-SQL strings to Proper Case, Camel Case, Snake Case, or Kebab Case”

  1. Interesting.  We've got some homemade functions that try to get to proper case, with varying results.
    How does your product handle a name like Manfred Albrecht Freiherr von Richthofen (aka The Red Baron), where "von" is properly lower case?
    Or a name with a capital in the middle, such as a Dutch name like VanDyke, which is sometimes Van Dyke or sometimes van Dyke?
    And what about address systems like those in Washington DC or Grand Rapids MI, where "NE" or "SW" is part of the address?  Ours requires special coding so it doesn't convert it to "Ne" and "Sw".

Leave a Reply

Your email address will not be published. Required fields are marked *