• So many different solutions... suggests SQL should have a proper case function of it's own?

    Many moons ago I came up with this - our need is quite straightforward, lower case and capitalise each word delimited by spaces and/or hyphens. Not pretty, but it does the job it's designed to do:

    CREATE FUNCTION [dbo].[ToProperCase](@string NVARCHAR(4000)) RETURNS NVARCHAR(4000)

    AS

    BEGIN

    SET @string = LOWER(LTRIM(RTRIM(@string)))

    DECLARE @i INT

    SET @i = ASCII('a')

    WHILE @i <= ASCII('z')

    BEGIN

    SET @string = REPLACE( @string, ' ' + CHAR(@i), ' ' + CHAR(@i-32))

    SET @string = REPLACE( @string, '-' + CHAR(@i), '-' + CHAR(@i-32))

    SET @i = @i + 1

    END

    IF (ASCII(LEFT(@string, 1)) BETWEEN ASCII('a') AND ASCII ('z'))

    BEGIN

    SET @string = CHAR(ASCII(LEFT(@string, 1))-32) + RIGHT(@string, LEN(@string)-1)

    END

    RETURN @string

    END