Re: Sequence numbering

Tech-Archive recommends: Fix windows errors by optimizing your registry



Could you try using a column with a IDENTITY column. Your problem is because
many threads accessing the sproc at the same time will get the same ID.

at the same time, 2 or more threads execute the SELECT and get the same ID,
because the UPDATE following it has not been called.

With an IDENTITY column, you could do this:

INSERT INTO [EDI].[Common].[TP_Sequence]
.......


select @@identity as Sequence

"Tom" <fishingrod45@xxxxxxxxxxx> wrote in message
news:1168015048.583819.304410@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
We have a stored procedure that is called when a unique sequence number
is required, it is pasted below. The SP is called within a map, on
each ClaimHeader record written. When multiple orchestrations are
initiated, sometimes there are resulting records that share the
'unique' id. [That is the problem.] For example, if 113 records
execute the SP, 108 of them are unique and 5 records share the same
'unique' id. Is there a better way to control sequencing within a map
on records inserted via the SQL adapter? Yes we do use the
autoincrement field so we are able to get the records inserted,
regardless, but we want the unique id to be unique. We believe that a
possible cause may be that several SP commands may be blending into one
(?) as multiple instances of the orchestration are blasting through
biztalk and SQL server is unable to distinguish the SP execute commands
as separate.

The reason the unique id is needed is to retain history on same
ClaimNumbers within the DB, but each -inbound- file will contain unique
ClaimNumbers, so as long as each claim is assigned the 'unique' id the
different versions of each ClaimNumber can be distinguished. This
didn't become a problem until we de-batched our inbound claims file.


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[usp_SELECT_Sequence_from_TP_Sequence]
-- @SendID|@RecID|@Trans
(@SendID varchar(20),
@RecID varchar(20),
@Trans Varchar(4)
)
AS

declare @Seq BigInt

SELECT @Seq = Sequence from [EDI].[Common].[TP_Sequence]
where
([SenderID] = @SendID and [ReceiverID] = @RecID and [Transaction] =
@Trans)

if @Seq > 0 begin
UPDATE [EDI].[Common].[TP_Sequence]
SET
[Sequence] = @Seq + 1
where
([SenderID] = @SendID and [ReceiverID] = @RecID and [Transaction] =
@Trans)
end else begin
-- Here is a new Send/Rec ID pair, insert it
insert into [EDI].[Common].[TP_Sequence]
([SenderID]
,[ReceiverID]
,[Transaction]
,[Sequence])
VALUES
(@SendID, @RecID, @Trans, 1
)
set @Seq = 1
Select @Seq as Sequence
end
Select @Seq as Sequence

Thanks,
Tom



.



Relevant Pages

  • Sequence numbering
    ... We have a stored procedure that is called when a unique sequence number ... Is there a better way to control sequencing within a map ... ClaimNumbers within the DB, but each -inbound- file will contain unique ... declare @Seq BigInt ...
    (microsoft.public.biztalk.general)
  • Re: Need help calculating queries & reports
    ... type, NOT a string type since string ... table2 based on the start/ stop sequence is not adding up correctly. ... seq# is a text field and time are numeric fields from table2. ...
    (microsoft.public.access.queries)
  • Re: AfxBeginThread startup times and overhead
    ... > I have a need that each thread knows the sequence in which its startup ... threads startup routines are called. ... unsigned int tf(LPVOID seq) { ...
    (microsoft.public.vc.mfc)
  • Re: Help with calculating time
    ... Microsoft Excel MVP ... in column D from Ref sheet. ... input their ID, date, part#, side, start sequence & stop sequence ... ID date part# side start seq stop seq ...
    (microsoft.public.excel.misc)
  • Re: Primary keys
    ... gaps in the sequence. ... Don't even assume an IDENTITY column will be unique ... unless you have a unique constraint on it. ...
    (microsoft.public.sqlserver.server)