This function is to you from Richard Oznebaugh
CREATE FUNCTION ProperCase(@STRING VARCHAR(8000))
RETURNS VARCHAR(8000) AS
BEGIN
DECLARE @PROPER VARCHAR(8000), @NUMBER INT
SET @PROPER = ''
SET @NUMBER = 0
WHILE @NUMBER <= LEN(@STRING)
BEGIN
SET @PROPER = @PROPER +
CASE
WHEN @NUMBER = 1 THEN UPPER(SUBSTRING(@STRING, @NUMBER, 1))
WHEN @NUMBER > 1 AND SUBSTRING(@STRING, @NUMBER - 1, 1) = ' ' THEN UPPER(SUBSTRING(@STRING, @NUMBER, 1))
ELSE LOWER(SUBSTRING(@STRING, @NUMBER, 1))
END
SET @NUMBER = @NUMBER + 1
END
RETURN @PROPER
-- USAGE:
-- SELECT dbo.ProperCase('STRING IN ALL CAPS')
END
No comments:
Post a Comment