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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to pad-fill a counter 1

Status
Not open for further replies.

lisaharris

Programmer
Feb 12, 2007
130
US
I have a daily table that is created by a make-table query from entries into a master table, and it needs to be numbered each day starting at 1. The numbers must have 0's filling the field to 7 bytes, such as 0000001, 0000002, etc. There are usually 2-300 records in the daily table.

Is there a way to accomplish this?

__________
It's better to have loved and lost than live with the idiot for the rest of your life.
 
Do you want those leading zeros stored in the table or do you just want to see them when you retrieve the data?

If you want them in the table then you will need to use a text field. Numeric fields (e.g. single, double, long, etc.) do not store leading zeros.

Since relational databases have no notion of intrinsic ordering of records, most processes to do this are multi-step activities. Here are a few ideas ...

#1
- Add an autonumber to the table after you run the MAKE TABLE.
Code:
ALTER TABLE NewTable ADD FIELD aNum Counter(1,1)
- Write a query to display the records with leading zeros
Code:
Select Format(aNum, "0000000") As RecNum, ...

#2
- If there us a unique field in the new table then write a Rank query
Code:
SELECT A.UniqueField, 

       Format((Select Count(*)+1 
               From NewTable As B 
               Where B.UniqueField < A.UniqueField),"0000000") AS RecNum

FROM NewTable AS A
 
Golom - your #2 solution is just what I needed!! Thank you so much!!

__________
It's better to have loved and lost than live with the idiot for the rest of your life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top