Friday, June 3, 2016

Use ProperCase Function in SQL Server

//String Proper display
create function properCase(@string varchar(8000)) returns varchar(8000) as

begin


    set @string = lower(@string)

    declare @i int

    set @i = ascii('a')

    while @i <= ascii('z')

    begin

        set @string = replace( @string, ' ' + char(@i), ' ' + char(@i-32))

        set @i = @i + 1

    end

    set @string = char(ascii(left(@string, 1))-32) + right(@string, len(@string)-1)
    return @string

end

=======================================================

select  dbo.properCase('this iS a teSt.')

=======================================================

O/P:=  This Is A Test.

No comments: