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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 SQL Locking
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

30 Posts

Posted - 02/05/2013 :  23:36:22  Show Profile  Reply with Quote
A table is used for storing current number of Sales Order

| 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.

Very Important crosS Applying yaK Herder

52326 Posts

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


SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000