
--DROP FUNCTION udf_TitleCase	--DROP the Function

--CREATE FUNCTION udf_TitleCase (@ToConvert VARCHAR(7999))	-- Input argument
--RETURNS VARCHAR(7999)	-- Output of Function
--AS
--  BEGIN	-- Commence the string conversion

--	DECLARE @CurrentPosition INTEGER
--	SET @CurrentPosition = 1
	
--	SELECT @ToConvert = UPPER(SUBSTRING(@ToConvert,1,1)) + LOWER(SUBSTRING(@ToConvert,2,LEN(@ToConvert)-1)) + ' '
	
--	WHILE @CurrentPosition < LEN(@ToConvert)
--	  BEGIN
--		SELECT @CurrentPosition = CHARINDEX(' ',@ToConvert,@CurrentPosition)
--		SELECT @ToConvert=SUBSTRING( @ToConvert,1,@CurrentPosition)
--			+ UPPER(SUBSTRING( @ToConvert, @CurrentPosition+1,1))
--			+ SUBSTRING( @ToConvert,@CurrentPosition+2, LEN(@ToConvert) - @CurrentPosition+1)	
--		SELECT @CurrentPosition = @CurrentPosition+1
--	  END
--	RETURN @ToConvert
--END

SELECT dbo.udf_TitleCase('MARY HAD A LITTLE AND IT''S FLEECE WAS WHITE AS SNOW')
