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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:12:10+00:00 2026-05-21T17:12:10+00:00

I have a SQL Record that has number that are all out of order

  • 0

I have a SQL Record that has number that are all out of order (has gaps) for example: 1,2,3,7,9,11…..
I would like to get only the first missing number.

I tried something like this but I just don’t know SQL to make it work correctly.

strQuery = "SELECT N as NextNum FROM LOADS WHERE N > 0 AND N <= (SELECT MAX(LOAD_NO) FROM @LOADS) AND N NOT IN (SELECT LOAD_NO FROM @LOADS)"
objNextNum.Open strQuery
lastLoadNo= objNextNum("NextNum")
response.write "NEXT LOAD NUMBER IS: " & lastLoadNo

I found that example on a ms website but I cannot get it to work.

Thanks for any help!!!

  • 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-21T17:12:12+00:00Added an answer on May 21, 2026 at 5:12 pm

    saw this somewhere, can’t remember where though, or i’d give proper attribution, but you should be able to use this:

    SELECT  TOP 1
            LOAD_NO + 1
    FROM    LOADS mo
    WHERE   NOT EXISTS
            (
            SELECT  NULL
            FROM    LOADS mi 
            WHERE   mi.LOAD_NO = mo.LOAD_NO + 1
            )
    ORDER BY
            id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have date range data in SQL DB table that has these three (only
I have a SharePoint external list that points to a 100,000 record SQL table.
I have an ADOQuery that inserts a record to SQL Server 2005 table that
I have 3 similar SQL queries that each will bring back 1 record with
I have a list of record Id's that I want to retrieve from Sql
I have an SQL query that returns all companies records ignore the ones with
Background: I have an object that has a number of properties that are other
I have a contact entity that has >1 phone number contact[contact, name, cell,work,home...] and
I have a field in my SQL Server 2008 table that is auto number
I am writing a SQL query that I would like to add a column

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.