0

MySql Datas;

   ID       Fname         Lname     
+------+-------------+-----------+
+  1   +    emre     +  surname  +
+  2   +    naMe2    +  suRnaMe2 +
+  3   +    namE3    +  SurnamE3 +
+ 1980 +    nAmE3    +  suRNamE3 +
+------+-------------+-----------+

I want to:

   ID       Fname         Lname     
+------+-------------+-----------+
+  1   +    Emre     +  Surname  +
+  2   +    Name2    +  Surname2 +
+  3   +    Name3    +  Surname3 +
+ 1980 +    Name4    +  Surname4 +
+------+-------------+-----------+

How can I make the editing process? - Is it possible with SQL Query?

Thank you!

John Woo
  • 258,903
  • 69
  • 498
  • 492
Saracoglu
  • 37
  • 8
  • 1
    1. http://whathaveyoutried.com, 2. learn about `UPDATE` queries. – Tomasz Kowalczyk Oct 05 '12 at 08:21
  • 2
    http://stackoverflow.com/questions/4263272/capitalize-first-letter-mysql – MrCode Oct 05 '12 at 08:23
  • 1
    This topic is already discussed here. [Capitalize first letter][1] [1]: http://stackoverflow.com/questions/3278207/mysql-capitalize-first-letter-of-each-word-in-existing-table – Palanikumar Oct 05 '12 at 08:30
  • Even though unicode characters will behave as expected note that uppercase of `i` will become `I` (dotless i) and lowercase of `I` will become `i` if you go about using standard SQL case functions. If you have Turkish names there you might want to use some conditions in your query. – inhan Oct 05 '12 at 08:38

3 Answers3

3

Try simulating it,

SELECT CONCAT(UPPER(SUBSTRING(Fname, 1, 1)), LOWER(SUBSTRING(Fname FROM 2))) AS properFirstName,
       CONCAT(UPPER(SUBSTRING(Lname, 1, 1)), LOWER(SUBSTRING(Lname FROM 2))) AS properLastName
FROM table1

SQLFiddle Demo

UPDATE tableName
SET Fname = CONCAT(UPPER(SUBSTRING(Fname, 1, 1)), LOWER(SUBSTRING(Fname FROM 2))),
    LName = CONCAT(UPPER(SUBSTRING(Fname, 1, 1)), LOWER(SUBSTRING(Fname FROM 2)))
John Woo
  • 258,903
  • 69
  • 498
  • 492
1

You can use something like that:

UPDATE table
SET Fname = CONCAT(UCASE(LEFT(Fname, 1)), LCASE(SUBSTRING(Fname, 2))),
    Fname = CONCAT(UCASE(LEFT(Lname, 1)), LCASE(SUBSTRING(Lname, 2)));

This should be update all your value:

  1. wOrld will become World
  2. Help will remain Help
  3. sEE YOU later1 will become See you later1

I suggest you to try it on a backup table before to use it on the main one.

Marco Pace
  • 3,820
  • 19
  • 38
0

Check This is working .

First letter of a string to a capital

UPDATE table SET field = CONCAT(UPPER(LEFT(field, 1)), SUBSTRING(field, 2))

and if you want to have all other characters lowercased:

UPDATE table SET field = CONCAT(UPPER(LEFT(field, 1)), LOWER(SUBSTRING(field, 2)))

Nirav Ranpara
  • 13,753
  • 3
  • 39
  • 54