MySQL query question

software development

#1

Query question? That seems redundant. But I digress…

I have an oldish database that’s all in lowercase. I wish to capitalize the first letter in each name in the Name column.

Does anyone know of a query in MySQL that could accomplish this?
I know that Oracle has the INITCAP function and that MySQL has nothing like it, but might there be a longer query that could imitate that?
I Googled several search terms, came up with one possible solution, and was given a syntax error for my troubles.

Any thoughts? It would really make my life so much easier. Heh!


#2

Why bother? Wouldn’t it be easier to simply make the change at the moment you extract the data? In PHP, you could do it with the ucfirst() function.


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#3

Here’s a statement that will do it:
UPDATE tablename
SET Name = CONCAT(UPPER(LEFT(Name,1)),SUBSTRING(Name FROM 2));

here’s the same thing spread out to (hopefully) make it easier to figure out what’s going on:

UPDATE tablename SET Name = CONCAT( -- # put the next two substrings together UPPER(LEFT(Name,1)), -- # capitalize first letter SUBSTRING(Name FROM 2) -- # grab rest of string );
–jim

markup is on, but there doesn’t seem to be a way to use a fixed-width font, I guess “you don’t always get what you want” & all that


#4

If you read the FAQ section, you will see you can use a PRE tag to make things look like this:

UPDATE tablename SET Name = CONCAT(UPPER(LEFT(Name,1)),SUBSTRING(Name FROM 2));It still seems like overkill to me. Much easier to use the PHP function.


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)


#5

well, looks like asking the question worked, because you’re right, markup is now enabled.

I tried editing that post ten different ways w/ combinations of <?PHP,[code],<html and
nothing would show up in the preview.

[color=#CC0000]L[/color][color=#00CC00]o[/color][color=#0000CC]o[/color][color=#CC6600]k[/color][color=#000000]i[/color][color=#0000CC]n[/color][color=#CC0000]g[/color] [color=#00CC00]b[/color][color=#0000CC]e[/color][color=#CC6600]t[/color][color=#000000]t[/color][color=#0000CC]e[/color][color=#CC0000]r[/color] [color=#00CC00]a[/color][color=#0000CC]l[/color][color=#CC6600]r[/color][color=#000000]e[/color][color=#0000CC]a[/color][color=#CC0000]d[/color][color=#00CC00]y[/color][color=#0000CC]![/color]

–jim


#6

You have my profound and sincere thanks for pointing that out. I have fixed the error to make sure I don’t suffer any additional embarrassment. I simply don’t know what I would do if I didn’t have you keeping an eye on everything I do - probably kill myself in despair, I should imagine.


Simon’s website
Save $100 on 1-year plans with promo code [color=#CC0000]SCJESSEY100[/color] (details)