I'm trying to write a trigger for a database that will capture the previous value of a field and, on insert of data from the app, increment that field by 1.
This field is similar to a check number, and the first record in the database will not be 1, it will be something like 386651. I'd like to be able to grab that as my initial starting number and increment each record thereafter by 1.
I do have a record identifier set up that is separate from this value.
There will be a couple hundred records imported into this table before it goes live for data entry. It is at this point that the trigger will need to be in place to continue sequentially assigning a "document number" to these records.
So far, everything I've tried either errors out or starts at 1 regardless of whether or not I have select max() in the trigger.
Obviously I am just getting my feet wet with SQL triggers, but have had success creating them in the past. However, this has me stumped.
This field is similar to a check number, and the first record in the database will not be 1, it will be something like 386651. I'd like to be able to grab that as my initial starting number and increment each record thereafter by 1.
I do have a record identifier set up that is separate from this value.
There will be a couple hundred records imported into this table before it goes live for data entry. It is at this point that the trigger will need to be in place to continue sequentially assigning a "document number" to these records.
So far, everything I've tried either errors out or starts at 1 regardless of whether or not I have select max() in the trigger.
Obviously I am just getting my feet wet with SQL triggers, but have had success creating them in the past. However, this has me stumped.
Comment