Hi AllI have a table with a list of job numbers: JobID JobCode Issued IssuedTo1 AAA 1 Mike2 AAB 0 null3 AAC 0 null4 AAD 0 null
etcI have a web application having to get the next available job number (where issued = 0).This is the simple way to allocate the next job:set @JobID=select top 1 JobID from Job where Issued=0update Job set Issued=1, IssuedTo='John' where JobID=@JobID
However, on a threaded web application, one job is allocated to more than one person because there is nothing to prevent another select from the Job table before the update executes.I've changed the code to this:begin transactionupdate Job set Issued=1, IssuedTo='John' where JobID in ( select top 1 JobID from Job where Issued=0)select max(JobID) from Job where IssuedTo='John'commit
However now I get repeated deadlocks happening here, which is a frustration to handle and debug.What would you recommend is the best way to issue JobIDs from the Job table?