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 7865413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:04:48+00:00 2026-06-03T00:04:48+00:00

I have a table called SharedNumber , which has only one field – an

  • 0

I have a table called SharedNumber, which has only one field – an integer number called LastNumber which can have one and only one entry.

There are about 40 or 50 odd completely separate Access databases that use this LastNumber entry as a common reference point. It is essentially being used to manually generate unique primary keys for a system that isn’t able to generate them by itself. It is ugly and messy, and I am in the process of gradually weaning them off one by one, but in the interim I need to build a process in SQL Server which would reference this same entry.

I am dealing with the following:

1.

The shared number table:

create table SharedNumber
( 
    [LastNumber] int not null
) ON [PRIMARY]


Insert into SharedNumber
values
(234) --This is the most recent shared number

2.

An input data table (InputTable) that will continuously receive new entries, and for which new ContractID fields values need to be generated manually by incrementing LastNumber. For simplicty, let’s say this table is uniquely defined on Name.

create table InputTable
(

    [ContractID] int NULL,
    [Name] varchar(50) not null
 ) ON [PRIMARY]


Insert into InputTable
values
(101,'ABC'),
(102,'DEF'),
(NULL,'GHI'),
(NULL,'JKL'),
(NULL,'MNO')

Entries ‘GHI’, ‘JKL’ and ‘MNO’ need ContractID values, so I want to incrementally create new numbers for them, based on LastNumber, and then update LastNumber to the last one that was generated. The eventual result I want is:

ContractID    Name
101           ABC
102           DEF
235           GHI
236           JKL
237           MNO


LastNumber
237

Anyone have any ideas on a good way to do this?

  • 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-03T00:04:49+00:00Added an answer on June 3, 2026 at 12:04 am

    One option would be to do this directly in the DDL for the contract table. This uses two columns and a computed column:

    create table whatever (
        BuiltInContractId int identity(1000000,1) not null, -- the 1000000 is just to set a range for contract ids
        OverrideContractId int, -- what a user inputs,
        ContractId as coalesce(OverrideContractId, BuiltInContractId),
        . . .
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table called FinalForgotten which only contains one field called aname. The field
i have table called as Support, which have a field named Name and contains
I have table called posts in my DB. Each post has field called social_network
I have a table called BlogPost which has a 1-to-many relationship with the Comment
Have a table called person. which has personid and contactid. if a person is
I have a table called Shoppings in my SQL db. This one has a
I have table called location with a field area. This field can contain various
I have a table called ApprovalTasks... Approvals has a status column I also have
I have table called Direccion other called Cliente each one defined like this public
I have table called page which represents every single page in my website. page_id

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.