How can I make the following always return in proper case? First Character to upper case.

How do I change a first and last name that are in uppercase to Proper or Title case where the first character of the first and last name are capitol and the rest lower case. This is done in a Stored Procedure. Thanks.
Who is Participating?
momi_sabagConnect With a Mentor Commented:
select lower(your_column)
from your_table

will return the name in all lower case
select upper(left(your_column,1)) + lower(substring(your_column,2, charindex(',', your_column) -1)) +
     upper(left(your_column, charindex(',', your_column)+1)) + lower(substring(your_column,charindex(',', your_COLUmn)+1, len(your_column)))
expertsexchangehunterAuthor Commented:
Here is my code
select upper(left(FirstName,1)) + lower(substring(FirstName,2, charindex(',', FirstName) -1)) +
     upper(left(LastName, charindex(',', LastName)+1)) + lower(substring(LastName,charindex(',', LastName)+1, len(LastName)))

here is what happened when I ran it with a valid First and Last name
Invalid length parameter passed to the substring function.
What is wrong with my code?
expertsexchangehunterAuthor Commented:
I used
select upper(left(FirstName,1)) + lower(substring(FirstName,2, len(FirstName)-1)) + ' ' +
upper(left(LastName,1)) + lower(substring(LastName,2, len(LastName)-1))
to get the desired results
Question has a verified solution.

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.

All Courses

From novice to tech pro — start learning today.