I suggest you try the code that I posted on my blog a while ago. I suspect that it will satisfy your requirements very well, and will also work better than many other methods.
Correct work with SQL Server
CREATE FUNCTION dbo.Proper(@DATA VARCHAR(8000)) RETURNS VARCHAR(8000) AS BEGIN DECLARE @Position INT SELECT @DATA = STUFF(LOWER(@DATA), 1, 1, UPPER(LEFT(@DATA, 1))), @Position = PATINDEX('%[^a-zA-Z][az]%', @DATA COLLATE Latin1_General_Bin) WHILE @Position > 0 SELECT @DATA = STUFF(@DATA, @Position, 2, UPPER(SUBSTRING(@DATA, @Position, 2))), @Position = PATINDEX('%[^a-zA-Z][az]%', @DATA COLLATE Latin1_General_Bin) RETURN @DATA END
This function is slightly faster than most, because for every word that requires a capital letter, it is executed only once.
G mastros
source share