Technical Article

Function for Proper Case - Most easiest way

,

This function is used to manage the alphabet case, which means the first letter of all the words will be in caps.

You may find many scripts for this functionality, but this one is easy to readability and understandability.

Regards,

Vignesh Arulmani

create function fn_mng_alphacase(@inputstring varchar(8000)) 
returns varchar(8000) 
as
begin

declare @returnstring varchar(8000)

set @returnstring = lower(@inputstring)

declare @i int
set @i = ascii('a')

while @i <= ascii('z')
begin

set @returnstring = replace( @returnstring, ' ' + char(@i), ' ' + char(@i-32))
set @i = @i + 1
end

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

return @returnstring
end
go



select dbo.fn_mng_alphacase('This is a sample text for verifying the function manage alpha case')

Rate

3.33 (9)

You rated this post out of 5. Change rating

Share

Share

Rate

3.33 (9)

You rated this post out of 5. Change rating