Add Leading Zeros

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
Run an update query:

UPDATE TableName
SET FieldName = Right("000000000" & [FieldName], 9);
 
Are you sure you want 9 digits???

Your examples indicate you want 6 digits.

Adjust Ken's solution if required.
 
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
 
Back
Top