Many a times need arises to convert a string into proper case specially the names. Let’s have a look at a SQL Server function to convert text string to proper case.

The logic is to delimit strings on space(‘  ‘) into columns and then change the first letter of column values to upper case and then again convert the column values to space delimited string.

The below query converts the string into xml delimiting it based on space (‘  ‘).

The output of above query is shown below.

1_sql server function to convert text string to proper case

The string ‘sql server’ is converted to xml format under the element/column ‘String’.  The next step is to convert this to a table. This is done using below query.

2_sql server function to convert text string to proper case

To understand this method in detail refer to LINK

The next step is to convert first letter of each row into upper case and then create a space delimited list of the column values.

The output of above method is shown below. To get more details on this refer to LINK

3_sql server function to convert text string to proper case

Let’s now wrap this logic in a function as shown below.

 

Regards

Ahmad Osama

Like us on FaceBook Join the fastest growing SQL Server group on FaceBook

Follow me on TwitterFollow me on FaceBook