<jo*************@gmail.com> wrote in message
news:11*********************@y43g2000cwc.googlegro ups.com...
Hi people,
I've looked around but have not been to find an answer for my question.
I'm looking to force a length of 4 on an integer field. Example if the
field contains an 11, I would like to show it as 0011, or a 9 to show
it as 0009. What do I need to do?
I am assuming:
a) You have an integer field.
b) That integer field never exceeds 9999 (four digits).
c) You want to query this integer field and have it display padded with
leading zeros as necessary to fill out to four digits.
If a, b, and c, are true - I would use the LPAD (left pad) function thus:
SELECT LPAD({field}, 4, '0') As `FourDigitInt`
You will, of course, modify that to your liking.
The drawback with LPAD() is that if your field value exceeds 9999, it will
truncate (drop digits) to get back down to 4 digits.
Thomas Bartkus