I use the following stored procedure to assign the next invoice number in my applcation:
This procedure has been used for months without incident but today it skipped 5 numbers in a row, i.e., it skipped from 2545457 to 2545463. At the time it happened the system was "running slow" but only one person was entering invoices. Anyone have any ideas as to why this would happen? Also a critique of the procedure used as well as suggested alternatives to handing out sequential numbers without gaps would be appreciated.
Code:
CREATE PROCEDURE InvoiceNewInvoice
@nextinv int output
AS
set nocount on
while 1=1 begin
select
@nextinv = nextinv
from
system
where
pkey = 1
update
system
set
nextinv = nextinv + 1
where
pkey = 1 and
nextinv = @nextinv
if @@rowcount = 1
break
end
This procedure has been used for months without incident but today it skipped 5 numbers in a row, i.e., it skipped from 2545457 to 2545463. At the time it happened the system was "running slow" but only one person was entering invoices. Anyone have any ideas as to why this would happen? Also a critique of the procedure used as well as suggested alternatives to handing out sequential numbers without gaps would be appreciated.