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

  • Home
  • SEARCH
  • 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 6846821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:40:13+00:00 2026-05-27T00:40:13+00:00

I need to identify missing products who’s numbers are sequential. In other words, there’s

  • 0

I need to identify missing products who’s numbers are sequential. In other words, there’s a set of products that are sold each with a unique number at each of our stores. The end user wants a report that will identify the missing widgets in a date range.

Store   Product Number
Store 1  Widget   100
Store 1  Widget   101
Store 1  Widget   102
Store 1  Widget   104
Store 2  Widget   201
Store 2  Widget   202
Store 2  Widget   203

I thought the best way to do this is to obtain the MAX(Number) and the MIN(Number) and then populate a table variable with all of the numbers in the sequence. If the Widget Number from the table variable doesn’t exist in the Product table, I would return the number and mark it as missing.

However; our DBA is very much against Cursors and I know WHILE loops take a lot of overhead. Plus, I’m not sure how to do this on a by store basis.

Does anyone know of the way to do this in a set based manner?

The widgets themselves have numbers, so when you sell widget #1, the next widget you sell should be widget #2. However; sometimes, that doesn’t happen and widget #3 is sold – widget #2 is missing and not in the database. I need to identify on a report that widgets #1 and #3 were sold and #2 is missing.

  • 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-27T00:40:14+00:00Added an answer on May 27, 2026 at 12:40 am

    Updated Answer

    Sample code to create a table and working solution are below. Basically you do 2 EXISTS checks – to see if there are numbers higher than the current number, and there is not a number one higher than the current number.

    DECLARE @t Table (Store int, Product varchar(100), number int)
    INSERT INTO @t
    VALUES
    (1, 'Widget',   100),
    (1, 'Widget',   101),
    (1, 'Widget',   102),
    (1, 'Widget',   104),
    (2, 'Widget',   201),
    (2, 'Widget',   202),
    (2, 'Widget',   203)
    
    SELECT Store, Product, t.Number+1 as Missing
    FROM @t t
    WHERE EXISTS (SELECT 1 FROM @t t2
                  WHERE t2.Store = t.Store
                  AND t2.product = t.product
                  AND t2.number > t.number)
    AND Not Exists (SELECT 1 FROM @t t3
                    WHERE t3.Store = t.store
                    AND t3.product = t.product
                    AND t3.number = t.number + 1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i need to identify who raise an exception to handle better str error, is
I'm developing an iOS app, but i need to identify the user who made
My iOS app has a need to uniquely identify each device so it can
Is there any free software tool or combination that allows me to identify the
Need to identify each of these 'a' tag in div and bind an onclick
I need to identify users according to an URI subset. It has the following
We need to identify and then process switch/case statements in code based on some
I need to identify the P(rocess) ID of an executing batch file from a
I need to identify all html elements on a page in a browser agnostic
I have a need to identify comments in different kinds of source files in

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.