Question Locked

MS Access 2000 Leading zeros

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Is there a way of adding and storing leading zeros to a number in a table field without them being entered?

ie; 7001 to be stored as 007001 and
35035 stored as 035035

2 replies

by tony hopkinson

You'll need to make the column a char type if you want to store it, or you could just do it on output.

select replicate('0',6 - DataLength(Convert(VarChar(6),[myinteger]))) + Convert(VarChar(6),[myinteger])
from mytable
where [myinteger] = 7001
will give
007001 as the answer

Whether you do this on update or insert, or simply leave it for selecting, will depend mainly on convience I suspect.

This discussion is closed to new replies.