what database are you using? this isn't an ANSI SQL question
if it's msaccess, see
this thread
if it's mysql, that feature is built in to the auto_increment facility
if it's some other database, you may want to investigate doing it in your application logic, e.g. with a
transaction lock on retrieving the last number used
but the real question here is:
why do your numbers have to have that format?
what's wrong with invoice numbers that are not magically tied to the customer?