Tuesday, July 9, 2013

Find out the Lower caracter count in a string

CREATE

FUNCTION CountLowerCase

(

@input

nvarchar(50)

)

RETURNS

int

AS

BEGIN

declare @len int

declare @i int

declare @count int

declare @ascii int

set @len = len(@input)

set @i = 1

set @count = 0

while @i <= @len

begin

set @ascii = ascii(substring(@input, @i, 1))

if @ascii >= 97 and @ascii <= 122

begin

set @count = @count +1

end

set @i = @i + 1

end

return @count

END

/*Output*/

select

dbo.CountLowerCase('SQLserver2008')

output

=6


No comments:

Post a Comment