If you have control over the definition of the table in question, you can use the MySQL zerofill attribute . It allows you to define a numeric column filled with zeros.
If you don't have this control (and what you really should do anyway), add an add-on when querying values ββfrom a table:
SELECT LPAD(CONVERT(IntColumn,VARCHAR(3)),3,'0')
Thus, the integer is stored as a normal integer, as it should be, but in terms of what this query consumes, the integers are padded .
source share