?
Solved

Change MySQL text to Proper Case

Posted on 2009-04-29
3
Medium Priority
?
1,064 Views
Last Modified: 2013-12-07
Hi,

How to change case for text in MySQL tables.to proper case.

Some texts are written ok but others are written like: HELLO WORLD

I want it to be Hello World

Is there any statement that will do it?

Also how to change values for columns with double to be just integer.
for example 59.78 I want it to be 59 or even 60 it doesn't matter much since it will be an integer.

It's stored in MySQL as VARCHAR in the table and I can't change it to a number.


Thanks
0
Comment
Question by:majdolyan
  • 2
3 Comments
 
LVL 15

Expert Comment

by:oobayly
ID: 24265872
Proper case is a tad tricky using just SQL, the following method only works for a single word. The general consensus seems to be to use a scripting language outside of SQL.

As for the converting a varchar representing a double to an integer, use the following
SET @foo = "HELLO";
SELECT CONCAT(UCASE(LEFT(@foo, 1)), LCASE(SUBSTR(@foo, 2)));
// Returns Hello
 
SET @char = '1234.6';
SELECT CAST(ROUND(@char, 0) AS SIGNED);
// Returns 1235

Open in new window

0
 

Author Comment

by:majdolyan
ID: 24267037
oobayly,

Thanks for the tricks.

both examples will work for only one value, how can I implement them for a complete column?
0
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24267790
Just use them in your select query.
SELECT
  CONCAT(UCASE(LEFT(fldText, 1)), LCASE(SUBSTR(fldText, 2))) AS `Proper Text`,
  CAST(ROUND(fldDoubleText, 0) AS SIGNED) AS `Rounded Int`
FROM tblData

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question