Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Locking

Author  Topic 

swissivan
Starting Member

30 Posts

Posted - 2013-02-05 : 23:36:22
A table is used for storing current number of Sales Order

CurrentNumber
| name | prefix | current_number |
| SalesOrder | SO | 10 |

I got multiple users to access this row to get the latest number

INSERT INTO SalesOrder (id,field2,...) SELECT (prefix + RIGHT('000' + CAST(current_number AS VARCHAR(4)), 4)), value2,... FROM CurrentNumber

Then update the current_number to 11

How to add locking on this row to prevent two users create sales order with same number? Thanks for any comments.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-06 : 00:41:14
why do you need to implement it like this? why cant you make it computed based on autogenerating identity field?

see

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -