autonumber and year in one field ?


I have some problem with my (reg_number) field.

I have to fill up the field with autoincrement number + year.

But in next year i have to reset autoincrement number with first number and lastyear + 1

here the database sample :






i have no idea…please help me. thnx.


is it possible that get example?

I would make it a manual exercise. I would store the last used auto-increment number somewhere in the db and update it each time I need to create a new record.

This way you have full control over the number when a new year starts.

I would NOT use the db’s automatic auto-increment number, because you do not have much control over it - and the db often skip numbers when records were deleted or after a system crash or electrical power failure.

Also consider this option:

When you need to "increment’, get the latest number from the database (do some kind of filter/sort on the field), split it and create a new number. This is what I’ve seen done in a software generating invoices.

You can put such code in beforeSave/beforeValidate…