Technical Article

ASCII ProperCase Function

,

Another Proper case function that utilises the ASCII function to convert to Proper case

Useage

SELECT [dbo].[fnProperCase](' CONVERT tHis toPROpper cASE')

ALTER FUNCTION [dbo].[fnProperCase]
(
@InputString VARCHAR(2000)
)
RETURNS VARCHAR(2000)
AS

BEGIN

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

DECLARE @Returnvalue VARCHAR(2000)=''

DECLARE @i INT =1

DECLARE @Space INT

WHILE @i <= LEN(@InputString)
BEGIN

SELECT @Returnvalue +=CASE WHEN (@i =1 OR @i = @Space)
   THEN CHAR(ASCII(SUBSTRING(@InputString,@i,1))-32)
   ELSE SUBSTRING(@InputString,@i,1)
  END

SET @Space = CHARINDEX(' ',@InputString,@i)+1
SET @i +=1

END

RETURN @Returnvalue

END

Rate

2.5 (4)

You rated this post out of 5. Change rating

Share

Share

Rate

2.5 (4)

You rated this post out of 5. Change rating