This is written for Microsoft T-SQL, but should work with minor tweaks in most SQL environments. I only know of one guy who reads this blog who also writes SQL (besides me) ... but for him and whoever else may run across this, this will save you some time ...
The problem with most string handling in SQL Server (and other SQL environments) is that it invites programmers to write non-set based code. Every function I've ever seen to put a string into title case ('Something Like This') parses the string, character by character, and writes the output. Functional, sure, but slow (in a SQL environment) -- this code does the same thing, using set-based updates. It's about 15 times faster than the code it replaced:
First, put the string to be altered (Address, in this example) into lower case. I used a temp table while developing this --
SET Address = LOWER(Address)
UPPER the first character in each Address column --
SET Address = UPPER(LEFT(Address,1)) + RIGHT(Address,LEN(Address) -1)
Look for the occurrance of a space in the Address column ...
-- WHILE through the available addresses
(SELECT 1 FROM #TMP WHERE Address LIKE '% %')
-- Replace space plus a character with ~ plus an UPPERed character
SET Address = STUFF(
'~' + UPPER(SUBSTRING(Address,CHARINDEX(' ',Address) + 1,1))
WHERE Address LIKE '% %'
--When we're done, we replace the ~ with spaces.
SET Address = REPLACE(Address,'~',' ')
Conceptually this isn't difficult; lots of string handling code does similar stuff, just without the set-based orientation. The first update statement will update only the first case it encounters of the space + a character, so we keep hitting the recordset until there are no more spaces in it. Then we replace the ~ with spaces, and we're done.
In my environment I have further processing to do after this -- I have to make sure that directionals like 'NE' don't turn into 'Ne,' for example, that MacAdams Drive doesn't turn into Macadams Drive, and so on ... but for most simple title case scenarios, this should suffice, and run quickly -- as I said, about 15 times faster than the non-set based code it replaced.