Quantcast
Channel: CodeSection,代码区,SQL Server(mssql)数据库 技术分享 - CodeSec
Viewing all articles
Browse latest Browse all 3160

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

$
0
0

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:


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

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. You’ll find info here: http://www.sqldownunder.com/resources/sdutools

Let’s look at the output from the function:


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

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


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

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


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

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:


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

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.

We hope you’ll find these functions useful. More details are here:

http://www.sqldownunder.com/resources/sdutools


Viewing all articles
Browse latest Browse all 3160

Trending Articles