Skip to content
Advertisement

sql – Add 0 after a numeric value

I have columns in my sql table. I am wondering how can I add zero after numeric values in my columns. So for example:

I have values e.g 9, 2, 7, 10. I want to add a zero after these numbers. I want them to be 90, 20, 70, 100.

There are some values in the columns that already have 0s after them e.g 70, 20, 100. These ones should retain their values.

How do I go about this?

score table

Advertisement

Answer

Just multiple the column by ten (not sure what your table name is, edit that query):

UPDATE __TABLE__
    SET mt_ca1 = (mt_ca1 * 10),
        mt_ca2 = (mt_ca2 * 10)
WHERE mt_ca1 < 100 OR mt_ca2 < 100;

It is not clear if you want to add zeroes after only double-digit numbers or all numbers. MySQL has substring functionality though you’d need to clarify your needs.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement