dhornbein
dhornbein

Reputation: 214

strip 0 from all rows in single column MySQL

I want to TRIM(LEADING 0 FROM month) FROM table1

where table1 has column month with data formatted like so: 01, 02, 03

I would like to update the data so it is formatted as: 1, 2, 3, ...

Thanks!

Upvotes: 0

Views: 120

Answers (2)

ashicus
ashicus

Reputation: 1252

From the MySQL docs:

mysql> SELECT MONTH('2008-02-03');
-> 2

So, if you only have the month (and not the rest of the date), you could use:

SELECT MONTH(CONCAT('2010-', month, '-', '01')) FROM table1;

Source: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_month

Upvotes: 1

Abe Miessler
Abe Miessler

Reputation: 85056

Simplest way might be to just cast it to an int:

SELECT CAST(month as int) from table

Upvotes: 4

Related Questions