Usage
Let's say you have a table containing book titles but the data as entered in the
table are all in uppercase and you want to set the titles capitalization
properly. Here's an example of your list of book titles:
SELECT [Title]
FROM [dbo].[Books]
Title
------------------------------------------------------------
A BUSINESS GUIDE TO CUSTOMER RELATIONSHIP MANAGEMENT
A PRACTICAL GUIDE TO CRM
ACCELERATING CUSTOMER RELATIONSHIPS
ACHIEVING EXCELLENCE THROUGH CUSTOMER MANAGEMENT
COMPLAINT MANAGEMENT
THE CUSTOMER MANAGEMENT SCORECARD
USING MICROSOFT CRM
Using the user-defined function above, the book titles above can look like the following:
Title
------------------------------------------------------------
A Business Guide To Customer Relationship Management
A Practical Guide To Crm
Accelerating Customer Relationships
Achieving Excellence Through Customer Management
Complaint Management
The Customer Management Scorecard
Using Microsoft Crm
To produce this result, the query is as follows:
SELECT [dbo].[InitCap] ( [Title] ) AS [Title]
FROM [dbo].[Books]
As can be seen from the output, the first character in each word is converted to
uppercase while the rest of the characters of the word are all made to
lowercase. The same is the case for the word "CRM", as can be seen from
the book titles "A Practical Guide To Crm" and "Using Microsoft Crm".
Instead of maintaining it to all capital letters, it was changed to
"Crm". Since the user-defined function won't be able to know which words
need to be retained as all capital letters, these special cases have to be
handled manually.