Sunday, February 12, 2012

Auto increment after select?

I have two processes will continue to get the number from a table. After eac
h
get, the number should increment by 1, and the two processes need to be
getting a unique number. Is it possible to avoid the two processes get the
same number?Use locking mechansims to ensure that only one process gets to update the
count at any one time. For example, you can do an UPDLOCK on the table.
--
HTH,
SriSamp
Email: srisamp@.gmail.com
Blog: http://blogs.sqlxml.org/srinivassampath
URL: http://www32.brinkster.com/srisamp
"BntConan" <BntConan@.discussions.microsoft.com> wrote in message
news:0CB33A5A-3B3A-4DC6-BCCA-BED54594F42C@.microsoft.com...
>I have two processes will continue to get the number from a table. After
>each
> get, the number should increment by 1, and the two processes need to be
> getting a unique number. Is it possible to avoid the two processes get the
> same number?
>|||try this
declare @.Curr_Num int
Update Tbl set @.Curr_Num = CurrValue, CurrValue = Currvalue + 1
where < Condition >
select @.Curr_Num
tbl is the table from which u have to select the value.
and CurrValue holds the current value to be returned.
Tx

No comments:

Post a Comment