Add Leading Zeros

G

Guest

I want to add leading zeros to a column of text. They are unequal in length
and I want each record to have 9 place holders, i.e. 76, 309, 1245, 87356
convert to 000076, 000309, 001245, 087356.

Thanks for all solutions.
 
K

Ken Snell [MVP]

Run an update query:

UPDATE TableName
SET FieldName = Right("000000000" & [FieldName], 9);
 
V

Van T. Dinh

Are you sure you want 9 digits???

Your examples indicate you want 6 digits.

Adjust Ken's solution if required.
 
P

Pieter Wijnen

my version of Oracle LPAD

'assumes 1 char to PAD

Function LPAD(ByVal Inval as string, Optional ByVal TheLen As Long=10,
Optional ByVal PadChar as String=" ") as string

Dim Padstr as string
PadStr=String(Ord(PadChar),thelen)
LPAD=Left(PadStr,Len(PadStr-len(InVal)) & Inval)
end function

HTH

Pieter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top