2

I have to update one column from my user table . Current record in User Table

**id , user_name**
1    , sachin rathore
2    , dilip CHOUHAN
3    , GariMA JAIN

I want to update user_name column like this

1 , Sachin Rathore
2 , Dilip Chouhan
3 , Garima Jain

User column should be in titlize form means first letter of each word should be capital and remain small letter

Abe Miessler
  • 82,532
  • 99
  • 305
  • 486
user386660
  • 501
  • 1
  • 3
  • 12
  • possible duplicate of [MySQL - Capitalize first letter of each word, in existing table](http://stackoverflow.com/questions/3278207/mysql-capitalize-first-letter-of-each-word-in-existing-table) – Jordan Running Jul 28 '10 at 13:22

2 Answers2

2

Here's a query that will do it

UPDATE SET table SET user_name= CAP_FIRST(CONCAT(SUBSTRING_INDEX(user_name, ' ',-1), ' ', SUBSTRING_INDEX(user_name, ' ',1)))

It relies on a custom built function to capitalize each first letter, namely CAP_FIRST, as found here: http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/

Here's another one: http://forums.mysql.com/read.php?20,265978,266040#msg-266040

NullUserException
  • 83,810
  • 28
  • 209
  • 234
1

THere's no build in function that can transform text in this way. You'd need to write a script that will do it. For example PHP has ucwords() function that you could use.

http://www.php.net/manual/en/function.ucwords.php

Mchl
  • 61,444
  • 9
  • 118
  • 120