“Why doesn’t this function exist?”

We have all had the situation where there is a need for a little custom function to modify strings or do simple math on a column. Today I am going to show how to create a User Defined Function (UDF) in Microsoft SQL.

The function will allow you to put a space before Upper case (capital), letters. The function will read the input string character by character and insert spaces before a capital letter. Additionally the function provides the option to not a space between consecutive upper case letters, i.e SQL.

And the way to call the function is via a SELECT statement is as follows