I have a non primary key TicketNo. field in my SQL server database where the format is fixed but consist different formats e.g. Vou001..Vou002, TKO001…TKO002. for every record that comes in, I need to increment the last no. so the record after Vou002 is Vou003, after TKO004 is TKO005. How can I perform this task without using some sort of record counting method. Since the table will consist of different kinds of TicketNo Format I believe it’s not possible to get the last table value and add on it. Please kindly advice. Thanks.
Share
Each code here consists of 1 parts: a prefix (
Vou,TKPetc) and a number.Using any kind of MAX or “roll your own” won’t be concurrency safe for 2 concurrent/overlapping calls even with lock hints. And these will reduce performance too.
This DBA.SE question shows how to emulate sequences in SQL Server: https://dba.stackexchange.com/questions/3307/emulate-a-tsql-sequence-via-a-stored-procedure