Technical Article

Function returns String in Proper Case [CamelCase]

,

This is a generalised Function that will return a String in Proper Case [Camel Case]. Means Afetr every space, first later will be in UPPER Case.
Example:
Input String: 'microSoft sql server'
Output String: 'Microsoft Sql Server'

/*********************************************************
CREATED BY   :HARI NARAYAN SHARMA[Software Engineer]
Email        :  hnarayan@techaxes.com
                hari.bagra@gmail.com
CREATION DATE:MAR 30, 2007
PURPOSE     :TO CONVERT INPUT STRING IN CAMEL CASE
HOW TO USE   :SELECT dbo.CamelCase('hARi nARAyan shARMa')
**********************************************************/CREATE Function [dbo].[CamelCase](@Str varchar(8000))
RETURNS varchar(8000) As
Begin
Declare @Result varchar(2000)
SET @Str = LOWER(@Str) + ' '
SET @Result = ''

While 1=1
Begin
        IF PATINDEX('% %',@Str) = 0 BREAK
SET @Result = @Result+UPPER(Left(@Str,1))+SubString(@Str,2,CharIndex(' ',@Str)-1)
SET @Str = SubString(@Str,CharIndex(' ',@Str)+1,Len(@Str))
End
SET @Result = Left(@Result,Len(@Result))
Return @Result
End

GO

Rate

4.75 (8)

You rated this post out of 5. Change rating

Share

Share

Rate

4.75 (8)

You rated this post out of 5. Change rating