If SQL-Server has an 'Auto Number' datatype, how can I make an autonumber on Progress?
I'm having a hard time with this, for often I had concurent events that cause duplication on my autonumber which caused error as it is a unique field.
Please help....
Thanks for your reply.
I tried the sequence, and it it works. I thank you for that too
But I have another problem. Some of my friend shared the table with me and it's not possible for everyone of them to change their code shortly. So I use NEXT-VALUE on my own code, not on Database-Trigger.
The problem is when my friend manually add the autonumber using find-last and +1, my sequence will crash on this manually generated auto-number...
e.g.
me using NEXT-VALUE (sequence) get number 100.
friend useing FIND LAST and +1 will get 101.
me using NEXT-VALUE (sequence) get number 101 again......
now what should i do....
PS: CMIIW, each sequence has it's own counter, so if I use the same sequence for several tables it won't keep each table's last counter but will only have one sequence counter.
Agree but the quick and very dirty way of doing it could be
Code:
DEF VAR I AS INT.
I = NEXT-VALUE( Next-Cust-Num ).
FIND CUSTOMER WHERE CUST-NUM = I NO-LOCK NO-ERROR.
DO WHILE AVAIL CUSTOMER:
I = NEXT-VALUE( Next-Cust-Num ).
FIND CUSTOMER WHERE CUST-NUM = I NO-LOCK NO-ERROR.
END.
CREATE CUSTOMER.
ASSIGN Customer.Cust-Num = I.
As you can see in my code it tries to find a record with the new number and if a record is found it continues to increase the sequence until a record is not found.
In my idea Tom said the better thing to do. Make your decision and then align the code to this method. Try not to go into further troubles having different solutions ...
If you want, write some source code to use for create the new record and make all the others use that code ( inside it you will use sequence or whatever ). For maintenance purposes it is easier, i think.
If you dont think to use the sequence, it may be a good idea to remove it from the db so that no one will be able to use it anymore..
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.