reset auto generate from 1 when academic year changes [message #351450] |
Tue, 30 September 2008 21:33 |
rajuakula
Messages: 63 Registered: March 2005
|
Member |
|
|
Hi,
My academic year starts from December 1st to November 30th.
From dec 1st my comid should start from 1 and increase by 1 when new record is inserted, till nov 30th.Again from next dec 1st it should start from 1 and increment asusual.
plz. look at the data below
table1
comid
------------------
1
2
3
.
.
150
1
2
.
.
178
1
2
.
.
thanks,
[Updated on: Wed, 01 October 2008 00:53] by Moderator Report message to a moderator
|
|
|
|
|
|
Re: reset auto generate from 1 when academic year changes [message #351457 is a reply to message #351456] |
Tue, 30 September 2008 23:31 |
rajatratewal
Messages: 507 Registered: March 2008 Location: INDIA
|
Senior Member |
|
|
Quote: |
Hi,
Actually my comid is varchar datatype, I am picking the last character of the data which is numeric and then auto incrementing using max,substring functions.Now how should I do this according to my requirement?
thanks
|
Very bad method.
Now tell me what happens if 2 users try to insert the data
at the same time.Now both will be having the same numeric value
because of max.
Sequence will always generate a different value in multiuser
enviroment.
What i think that you are having a bad design.And using
cycle in sequence will not save your neck.
Rethink about your design.Why you need the same value again.
Regards,
Rajat
|
|
|
|
|
Re: reset auto generate from 1 when academic year changes [message #351463 is a reply to message #351462] |
Wed, 01 October 2008 00:01 |
rajuakula
Messages: 63 Registered: March 2005
|
Member |
|
|
yes, I tried your code.It is working but how do I restrict between the academic year.once academic year changes, it should start from 1 again.According the reply you sent, after 4, it is repeating again.In my case,I dont know how many records will be inserted by user between Dec 1st 2008 to nov 30 2009, might be 100 or 200 or more.once academice year completes then it should start again from 1.How do I need to implement this?
very urgent.
thanks
|
|
|
Re: reset auto generate from 1 when academic year changes [message #351465 is a reply to message #351463] |
Wed, 01 October 2008 00:13 |
rajatratewal
Messages: 507 Registered: March 2008 Location: INDIA
|
Senior Member |
|
|
You have to check everytime before generating value that
it's a new academic year or not.You can keep that value in a
table and check it with sysdate.
If it's new academic year you can reset the sequence value
by analysing it's current value and using alter command
to reset it's value.
google on sequences.
Check This
But i will again say rethink your design.It's not a scalable
solution.
Regards,
Rajat
|
|
|