Auto generate invoice number

P

peetersb

Hi,

What is the best way to generate a sequence number like:

2008-0001
2008-0002
....etc

I use sql server....


Thanks
Bart
 
R

Rick Lones

Hi,

What is the best way to generate a sequence number like:

2008-0001
2008-0002
...etc

I use sql server....

Well, one way would be to define your key field as (IsIdentity) = true, Identity
Increment = 1, Indentity Seed = e.g., 2008000000 or some such thing. But I do
not think any DBA would tell you that this is a very good idea, database design
wise. And of course you will have to reset the seed every year - do you really
want to buy into that?

Or, you can derive a string (or number) of the type you want programmatically,
but that means you have to save the state yourselv of "last sequence # used"
somewhere - which is what IsIdentity does for you. Really though, you should do
some reading on relational design and queries - the kind of thing you are
suggesting here is almost NEVER necessary, IMO.

For instance: just store the date in the invoice record - you can use it to
filter (by year as per your given example) and sort the records and could even
assign a sequence number after the sort if it is really needed. But I suspect
that you don't need the sequence number at all that sort by date will suffice.

HTH,
-rick-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top