auto increment a field 
Author Message
 auto increment a field

I inherited a customer table that gets appended once a week.
Previously the cust_id field was incremented by hand and that is out
of the question (since I have to do it now.)  We get about 100 - 250
new records a week.

I'm sure there is a way to find the highest value in a numeric field
increment by 1 then append the next record automatically.  I looked at
the white paper on how to do this by adding a counter field to screen
(Q106708) but I was unable to adapt it to do what I want.

The sys(2015) function gives me a unique value easily but I would
prefer the autonumber style of doing this.

Thanks          Chris



Wed, 02 Aug 2000 03:00:00 GMT  
 auto increment a field

Chris,

A lot of people use a separate id table with the key values for each table, and use a
UDF() to return the next value to use. This allows the id record to be locked in a
multiuser environment. If you are not multiuser you can get by with a function that does:

   select max(id) from customer into array laJunk
   return laJunk[1] + 1

By putting this code in a UDF you can change it out with a multiuser compatible routine if
needed in the future.

df    - (Microsoft FoxPro MVP) http://www.geocities.com/ResearchTriangle/9834/

Quote:

>I inherited a customer table that gets appended once a week.
>Previously the cust_id field was incremented by hand and that is out
>of the question (since I have to do it now.)  We get about 100 - 250
>new records a week.

>I'm sure there is a way to find the highest value in a numeric field
>increment by 1 then append the next record automatically.  I looked at
>the white paper on how to do this by adding a counter field to screen
>(Q106708) but I was unable to adapt it to do what I want.

>The sys(2015) function gives me a unique value easily but I would
>prefer the autonumber style of doing this.

>Thanks Chris



Wed, 02 Aug 2000 03:00:00 GMT  
 auto increment a field

I use 2 tables for this. One for the customer table and one to hold the last
key of the customer table or any other table for that matter. Whenever I
append a record to the customer table I just look up the last key in the
other table, add 1 and store it to the new rec.

Quote:

>I inherited a customer table that gets appended once a week.
>Previously the cust_id field was incremented by hand and that is out
>of the question (since I have to do it now.)  We get about 100 - 250
>new records a week.

>I'm sure there is a way to find the highest value in a numeric field
>increment by 1 then append the next record automatically.  I looked at
>the white paper on how to do this by adding a counter field to screen
>(Q106708) but I was unable to adapt it to do what I want.

>The sys(2015) function gives me a unique value easily but I would
>prefer the autonumber style of doing this.

>Thanks Chris



Thu, 03 Aug 2000 03:00:00 GMT  
 auto increment a field

I just keep a separate "config.dbf" file with whatever counters I need.
When I need to assign the next number (invoice, ID, etc) I get the
counter, add 1 to it, and put it back.

Quote:
        -----Original Message-----

        Posted At:      Saturday, February 14, 1998 3:39 PM
        Posted To:      exchange
        Conversation:   auto increment a field
        Subject:        auto increment a field

        I inherited a customer table that gets appended once a week.
        Previously the cust_id field was incremented by hand and that is
out
        of the question (since I have to do it now.)  We get about 100 -
250
        new records a week.

        I'm sure there is a way to find the highest value in a numeric
field
        increment by 1 then append the next record automatically.  



Sat, 05 Aug 2000 03:00:00 GMT  
 auto increment a field

Quote:

> I just keep a separate "config.dbf" file with whatever counters I need.
> When I need to assign the next number (invoice, ID, etc) I get the
> counter, add 1 to it, and put it back.

I dunno if this is implied, but I'll explicitly state that I put the UDF to
do what Jack says as a stored procedure in the DBC, and then have the
"Default Value" method of the field I want to increment call that Stored
Procedure.  That way no matter how records get appended, a unique number
gets into the field.

Eric Selje
eseljeATwiwd.uscourts.gov



Mon, 07 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Auto Increment Field

2. Auto-incrementing a primary key field

3. Auto Increment Field

4. Auto Increment Field

5. Auto-Incremented field

6. Auto-increment Field in Foxpro

7. auto-increment field

8. Auto Increment

9. Auto-Incrementing

10. Auto Incrementing Primary Key

11. How to make an auto-incrementing index

12. auto-incrementing a primary key

 

 
Powered by phpBB® Forum Software