Thursday, May 30, 2013

Sql function for Proper case

Create function properCase(@string varchar(8000)) returns varchar(8000) as    
begin    
 if len(@string)>0  
 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)    
 end  
        return @string    
end

call this funcrion as :

select dbo.ProperCase('AJAY')

result is:
Ajay

No comments:

Post a Comment