Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query to pad a text field. 1

Status
Not open for further replies.

salimnice

Technical User
Jun 7, 2005
3
US
I have a text field that contains a text value that is either 5 or six charters. I need a way to add a "0" to the first position of all the fields that are five charters in length. An example would be "50536" would become "050536" but "600001" would remain as "600001". Can anyone help me out with this?
 
UPDATE yourTable
SET yourField = "0" & yourField
WHERE Len(yourField) = 5;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Is there a way to do it within the query with a function?
 
So, you don't want to update your table.
You may try either this:
Expr1: Right("0" & yourField, 6)
Or this:
Expr1: Format(yourField, "000000")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top