• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generating number sequence ,

 
Harish Maridi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using struts framework, So I am posting this topic here.

My application insert a record in DB, while inserting it should generate a number sequence for that record.
for example: today I am inserting first record, the sequence should be 2008060001 (YYYYMM0001), second record 2008060002.
I am able to get up to YYYYMM, but the sequence I am unable to get it.
Can any body suggest me about it.
Thanks in advance.
-mark
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd suggest you create a table in your database with two rows: Year_month and seq_no. Whenever you generate a new record for your other table, look for a record in this table for the given year/month. If there is no record, insert a record for this year/month with a sequence number of "1" and return 1 as the sequence number. If there is a record, get the sequence number, add 1 to it, update the table with the new sequence number, and return the incremented sequence number to be used by the other table.
[ June 17, 2008: Message edited by: Merrill Higginson ]
 
Harish Maridi
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks ....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic