CREATE FUNCTION [dbo].[fnTitleCase]( @text AS varchar(8000) )
RETURNS varchar(8000)
AS
BEGIN
DECLARE @Reset bit;
DECLARE @Ret varchar(8000);
DECLARE @i int;
DECLARE @c char(1);
SELECT @Reset = 1, @i=1, @Ret = ”;
WHILE (@i <= len(@Text))
BEGIN
SELECT @c= substring(@Text,@i,1),
@Ret = @Ret + case when @Reset=1 then UPPER(@c)
else LOWER(@c) end,
@Reset = case when @c like ‘[a-zA-Z]’ then 0 else 1 end,
@i = @i +1
END
RETURN @Ret
END