Experts Exchange connects you with the people and services you need so you can get back to work.
CREATE FUNCTION fn_proper_case(@str as varchar(8000))returns varchar(8000) as
Returns the proper case (First letter capitalized, the rest smalls) of a string.
03-02-12 jhorn Original. http://weblogs.sqlteam.com/jeffs/archive/2007/03/09/60131.aspx
-- EXAMPLE OF HOW TO CALL
select dbo.ProperCase('this,my friends, is a test.wHat DO you think?i like shaquile o''neal')
This,My Friends, Is A Test.What Do You Think?I Like Shaquile O'Neal
-- TESTING ONLY
Declare @str varchar(8000) = 'IQBAL MEHRAM'
declare @Reset bit
declare @Ret varchar(8000)
declare @i int
declare @c char(1)
select @Reset = 1, @i=1, @Ret = ''
while (@i <= len(@str))
select @c= substring(@str,@i,1),
@Ret = @Ret + case when @Reset=1 then UPPER(@c) else LOWER(@c) end,
@Reset = case when @c like '[a-zA-Z]' then 0 else 1 end,
@i = @i +1
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.