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

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

swissivan
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

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

India
52325 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?

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
  Previous Topic Topic Next Topic  
 New 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.06 seconds. Powered By: Snitz Forums 2000