0

I am using mysql I want first letter of firstname capital and remaining characters in lower case the query i am using is

select  UPPER(LEFT(FirstName,1))+LOWER(SUBSTRING(FirstName,2,LENGTH(FirstName))) FirstName from colliers;

this gives answer 0, but it works perfectly in SQL server ..

mb1987
  • 437
  • 8
  • 21

3 Answers3

1

You have to use CONCAT(), instead of +

SELECT CONCAT(UPPER(LEFT(FirstName,1)),LOWER(SUBSTRING(FirstName,2,LENGTH(FirstName)))) FirstName from colliers
Arun
  • 941
  • 6
  • 13
1

You have to use concat(). "Plus sign" concatenation doesn't work in MySQL. You will probably end up with something like this :

select CONCAT(UPPER(LEFT(FirstName,1)), LOWER(SUBSTRING(FirstName,2,LENGTH(FirstName)))) FirstName from colliers;

By the way you don't need LENGTH(FirstName) in the SUBSTRING() function call. When the third parameter is omitted SUBSTRING() assume you want the rest of the string.

ForguesR
  • 3,558
  • 1
  • 17
  • 39
0

Just one more way to solve the problem!

I would use concat(), ucase()/upper(), lcase()/lower(), mid()/substring()

SELECT CONCAT (
        upper(mid(Firstname, 1, 1))
        ,lower(mid(Firstname, 2))
        )
FROM colliers;
Logan
  • 1,331
  • 3
  • 18
  • 41