Link to home
Start Free TrialLog in
Avatar of expertsexchangehunter
expertsexchangehunter

asked on

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.
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER CERTIFIED SOLUTION
Avatar of momi_sabag
momi_sabag
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of expertsexchangehunter
expertsexchangehunter

ASKER

momi
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?
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