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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:14:02+00:00 2026-05-15T13:14:02+00:00

Could you please help me with this one: In one of my scripts I

  • 0

Could you please help me with this one:

In one of my scripts I am inserting some data in to some table “Item”. One of the columns in the “Item” table is “ItemNumber”.

I want to be able to call some function (most probably a Stored proc) where it would return me a numeric number which I can use for the ItemNumber.

I CAN NOT use AutoIncrement because ItemNumber is unique and there might be a collision when in a differnt script I am inserting data in “Item”, which already has “ItemNumber”

I only know the Max number for the “ItemNumber” and I am free to use anything after that.

I need a table for this storedProc to store the next number to be used, right?

I was thinking of creating a one column table with the MaxNumber in it and a storedproc where it would return me the MaxNumber and also increment the MaxNumber by 1 for the next use

I need help writing the stored proc and it usage with in the INSERT INTO Item call.

EDIT:

Basically I am grabbing data from 5 old tables where ItemNumber is either NULL or set. For the ones which are set they are all unique numbers.
For the data where the ItemNumber is NULL I want to assign it, what the best approach?

Help please!

Thanks,

Voodoo

  • 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-05-15T13:14:03+00:00Added an answer on May 15, 2026 at 1:14 pm

    (Assuming SQL Server – probably applies to most SQL implementations)

    If you use IDENTITY constraint on your field, the server will not allow there to be duplicate instances. As one of the comments notes, the value is calculated on the server in this case, and your application does not (and under normal circumstances cannot) provide it.

    Note that the server does not guarantee that the numbers will be contiguous – should you do an insert, and abort the transaction, the value that would have been used would be ‘lost’ – the server will not offer it again.

    If you need to have contiguous ID numbers, you will need to have serlialised access to update the table, which you would need to manage and which would not be efficient. (You can still declare it to be an IDENTITY column, but would need to set IDENTITY_INSERT On for the table for each update.)

    Additional:

    Possibly a bit of a kludge, but might work for a one-off scenario.
    Have you considered copying the data into a new table, where the ID is set, then applying the IDENTITY constraint, and inserting the ones with NULL IDs (allowing the server to allocate them for you?)
    That might fix your specific issue here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Could anyone give me some help with this please? The content needs to appear
Could you please help me converting this c++ code into python: I am trying
Could anyone please help me convert this code to vb.net, I have tried it
Could someone please help me to convert this String into a Map ... String
Could someone please help explain why I can't get this to work? I properly
Could someone please help me in here, I'm just a beginner who want to
Could you please help me that this code doesn't work in IE? But this
Could someone please help meto improve this part of code? The string is something
Could you please help me out to find the correct deceleration rate for the
Could you please help me to get image upload working on a view with

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.