There are lots of ways to accomplish this. Here is one using a function:CREATE FUNCTION dbo.fn_format_case (@text_in VARCHAR(200))RETURNS VARCHAR(200)ASBEGIN DECLARE @char VARCHAR(1), @text_out VARCHAR(200), @pos INT If @text_in IS NOT NULL BEGIN SELECT @char = '', @text_out = '', @pos = 1, @text_in = UPPER(@text_in) WHILE @pos <= DATALENGTH(@text_in) BEGIN -- set @char to first character SET @char = SUBSTRING(@text_in, @pos, 1) -- if previous letter is already UPPER then lowercase current pos IF ASCII(SUBSTRING(@text_in, @Pos - 1, 1)) Between 65 And 90 BEGIN SET @char = LOWER(@char) END -- build output string, increment position SET @text_out = (@text_out + @char) SET @pos = (@pos + 1) END ENDRETURN(@text_out)END
Nathan Skerl