Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7836619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:13:57+00:00 2026-06-02T14:13:57+00:00

I have a table which contains header information for transactions. The transactions belong to

  • 0

I have a table which contains header information for transactions. The transactions belong to different projects.

In the header I have columns:

rhguid - uniqueidentifier
rhserial - int
rh_projectID - int

First I insert the row (there’s more columns)

Then I calculate the serial number for that project:

update responseheader 
set rhSerial = 1 + (select isnull(max(rhSerial), 0) 
                    from responseheader 
                    where (rhstatus = 0) AND (rh_projectID = 1234)) 
where 
   (rhGUID = <preassignedGUID>);

However when there are many transactions happening at the same time for a project I am finding duplicate rhserial values.

I’m doing this in classic ASP with SQL Server 2008.

Is there a better way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T14:13:59+00:00Added an answer on June 2, 2026 at 2:13 pm

    From your example, it doesn’t look like you’re using a transaction. My guess is that the SELECT portion of the statement is running as READ UNCOMMITTED, otherwise you would not see duplicates. There are ways to start transactions with ADO, but I prefer using stored procedures instead.

    Try implementing something like this:

    CREATE PROC dbo.ResponseHeader_Insert
      <more data to insert>,
      @ProjectID INT,
      @Status SMALLINT
    as
    
    insert responseheader (column names here)
    select <param values here>, isnull(max(rhSerial), 0) + 1
    from responseheader  
    where (rhstatus = @Status) AND (rh_projectID = @ProjectID))  
    

    If this doesn’t work for ya, try creating sequence tables (one for each sequence).

    create table <tablename> (
          SeqID int identity(1,1) primary key,
          SeqVal varchar(1)
    )
    

    Create a procedure to get the next identity:

    create procedure GetNewSeqVal_<tablename>
    as
    begin
          declare @NewSeqValue int
    
          set NOCOUNT ON
    
          insert into <tablename> (SeqVal) values ('a')
          set @NewSeqValue = scope_identity()
          delete from <tablename> WITH (READPAST)
    return @NewSeqValue
    end
    

    If there are too many sequence tables that need to be created or you want to create sequences on the fly, try this approach:

    Create table AllSequences (
          SeqName nvarchar(255) primary key, -- name of the sequence
          Seed int not null default(1), -- seed value
          Incr int not null default(1), -- incremental
          Currval int 
    )
    Go
    
    create procedure usp_CreateNewSeq
          @SeqName nvarchar(255),
          @seed int = 0,
          @incr int = 1
    as
    
    begin
    
          declare @currval int
          if exists (
                select 1 from AllSequences
                where SeqName = @SeqName )
    
          begin
                print 'Sequence already exists.'
                return 1    
          end
    
          if @seed is null set @seed = 1
          if @incr is null set @incr = 1
          set @currval = @seed
    
          insert into AllSequences (SeqName, Seed, Incr, CurrVal)
          values (@SeqName, @Seed, @Incr, @CurrVal)
    end
    go
    
    
    create procedure usp_GetNewSeqVal
    
          @SeqName nvarchar(255)
    as
    
    begin
          declare @NewSeqVal int
          set NOCOUNT ON
    
          update AllSequences
          set @NewSeqVal = CurrVal = CurrVal+Incr
          where SeqName = @SeqName
    
          if @@rowcount = 0 begin
                print 'Sequence does not exist'
                return
          end
          return @NewSeqVal
    end
    go
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view which contains (among other columns) a header name, and an
I have created a data table which contains 4 columns, 3 are strings and
I have a table which contains a list of ID's (int) and the date
I have table which contains double values stored in mysql database ...I need to
I have a table which contains my server status create table ServerStatus ( ServerId
I have a table which contains my ads that can be searched in sql-server-2008.
i have a table which contains a bunch of dynamically created radio button lists,
I have a table which contains house details called property. I am creating a
I have a table which contains unique indexes;lets say A B 1 1 1
I have a table which contains User IDs, Period IDs and Qty: User Period

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.