SQL Server has got in-built functions to convert the given string into LOWER() or UPPER() format but it does not provides any direct way to convert it to PROPER format. A string/text is said to be in a PROPER format if all the words in that string/text starts with a CAPITAL letter.
E.g. If a string is - “Hello, how are you?”,
String in Lower format = “hello, how are you?”
String in Upper format = “HELLO, HOW ARE YOU?”
and String in Proper format = “Hello, How Are You?”
Ideally, SQL Server is not the right place to implement this kind of logic, as string operations are costlier in SQL from performance perspective. it should be either implemented in the Front-End language or the Reporting Tool as this more related to the formatting. However, if this is to be implemented in SQL, the more preferred way is to use SQL-CLR function. It does not mean that we can not achieve this with T-SQL.
Today, I will share a simple T-SQL function, which could be used to convert any given string in PROPER format. Below is the script -
When the above script is used as –
we get the following result - Hello, How Are You?
The given script could be used to convert any string in PROPER format using T-SQL. However, I would personally prefer converting the string at the Front-End or in the Reporting tool to display the string in this format.