/    Sign up×
Community /Pin to ProfileBookmark

Generate Numbers

Hello:

I hope someone can help me out.

I have a table which stores client information. In this table I also need to store a field called case_number.

My client would like the case_number to be automatically generated when she adds a new client. And, she would like the case numbers to be sequential.

So if I have ClientA in a table with case number 2020 and I add ClientB to the table, I would like their case number to be 2021. And, if I add ClientC to the table, their case number sould be 2022. Etc.

Is it possible to write a script to generate a number in sequential order and store that number into a table?

If so, how do I go about scripting something like this?

Thank you in advance.

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 25.2007 — You could do it in the table by setting case_number to auto-increment.
Copy linkTweet thisAlerts:
@focus310authorAug 25.2007 — Hi,

I tried that approach. This was the error message I received.

#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key

I already have a primary key which is set to auto_increment. I need another field to increment as well and it needs to start incrementing from the number 2000.

The primary key in the table is the client_id.
Copy linkTweet thisAlerts:
@NogDogAug 25.2007 — Important question: can a given client ever have more than one case number? If so, then you need to get the case number out of the client info table and into a separate case table, with a third case-to-client relation table.

If not, then the easiest solution might be to insert the new client info record with a 0 or null value for case ID, do a mysql_insert_id() to get the client ID, then do an update to set the case number as that ID + 2000.

Of course, even simpler would be to just have one column as customer/case ID. You can define the column as auto-increment, with the first number being 2000 ("AUTO_INCREMENT = 2000" in the table options section of the create table SQL).
Copy linkTweet thisAlerts:
@focus310authorAug 25.2007 — Hi,

A client cannot have more than one case number. Should the client be a repeat client, he is considered a new client and will be assigned a new number.

I'll have to run the idea by the people if they care whether client ID and case number are the same.
Copy linkTweet thisAlerts:
@tcaAug 25.2007 — Hi,

A client cannot have more than one case number. Should the client be a repeat client, he is considered a new client and will be assigned a new number.

I'll have to run the idea by the people if they care whether client ID and case number are the same.[/QUOTE]


If the client ID and case number are the same how will you add a new case number to a returning client?

If you use a separate column for client ID and case number, you will have to re-enter the client information (or get it from the D? for the new case number. This can be done if you have some other unique client identification (such as SSN) so you can search the DB for the client info, insert it into a new record (with auto-incremented ID) and assign the new case number.

You have a conundrum.

TC
Copy linkTweet thisAlerts:
@Declan1991Aug 25.2007 — You could just get the highest number in the table and add one, but that is a bit slow, and using auto-increment would be preferred.
×

Success!

Help @focus310 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...