tags:

views:

208

answers:

2

How can I convert and update all my data in one colum from uppercase to uppercase just for the first letter of each word?

Need to update the database with the new values.

Thanks

+5  A: 

Looks like someone created a function for this,

CREATE FUNCTION CAP_FIRST (input VARCHAR(255))

RETURNS VARCHAR(255)

DETERMINISTIC

BEGIN
    DECLARE len INT;
    DECLARE i INT;

    SET len   = CHAR_LENGTH(input);
    SET input = LOWER(input);
    SET i = 0;

    WHILE (i < len) DO
     IF (MID(input,i,1) = ' ' OR i = 0) THEN
      IF (i < len) THEN
       SET input = CONCAT(
        LEFT(input,i),
        UPPER(MID(input,i + 1,1)),
        RIGHT(input,len - i - 1)
       );
      END IF;
     END IF;
     SET i = i + 1;
    END WHILE;

    RETURN input;
END;


SELECT  CAP_FIRST(
    'this is totally like   @ TEST 1 right!'
)

Which returns: "This Is Totally Like @ Test 1 Right!"

Link: http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/

meder
Thanks. That helps. But is there a query which I can run against my database which can update all the values? That would be the ideal solution.
I would allocate a new table to test with, and try something like:UPDATE TABLE SET column=CAP_FIRST(column)Though I admit I haven't done this before.
meder
A: 

this may help...

http://joezack.com/index.php/2008/10/20/mysql-capitalize-function/

alex