I have an INT field in my table, which I\'d like to select as a zero-padded string. So for example, 8 would come out as 008
, 23 as 023
and so on. I
If you want to achieve a minimum number of padding, without cutting the results of larger numbers, you'll need to use an IF
statement.
The example below will make sure all IDs have a minimum of three digits, while letting larger IDs still pass through untrimmed.
SELECT IF(id < 100, LPAD(id, 3, 0), id)