Jes Sie

Jes Sie

  • 742
  • 1.2k
  • 280.1k

What is the best way to increment a transaction number

Sep 20 2017 5:22 AM
I am currently developing a travel insurance system. In my table, I have a transaction number which should increment by 1 every transaction. I tried using the code below in my previous development but primary column ID jumps (e.g. before insert row number is 10 after insert row number becomes 12). The travel insurance that I currently developing will be used entire Laos country. That means I am expecting concurrent users of +/- 200.
  1. ALTER PROCEDURE [dbo].[spAutoGenerateMotorCINo]  
  2. AS  
  3. BEGIN  
  4.     declare @ID int, @RefNumber nvarchar(15);     
  5.     Select @ID = ISNULL(Max(Cast(RIGHT(MotorInsuranceID, 15) as int)), 0) + 1 from tblMotorInsurance_eCI;  
  6.     Select RIGHT(cast(@ID as nvarchar), 9);  
  7. END  
 Thank you in advance for any suggestions and recommendations.

Answers (1)