I have a column of numbers between 0 - 6 digits long. For those less than 6 I need to pad out with zeros to ensure they are all 6 digits i.e 12563 = 012563 or 23 000023 etc etc. Can someone recommend a solution?
To pad an integer with leading zeros to a specific length To display the integer as a decimal value, call its ToString(String) method, and pass the string "Dn" as the value of the format parameter, where n represents the minimum length of the string.
Padded numbers are frame numbers that have a specified number of digits, where 0s are used to fill the unused digits. For example, 5 digit padding myimage00002.ext.
Probably the easiest way to pad numbers with leading zeros would be to use the Format()
function, as in
Format(fieldName, "000000")
If you're searching on this (like for PIN numbers, where '12' would be represented as '000012' here's an example using Gord's correct answer;
SELECT CStr(Format(fieldName,"000000")) FROM table WHERE CStr(Format(fieldName,"000000"))="000012";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With