Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Query to obtain missing number

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-04, 16:29
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Query to obtain missing number

I've been trying to figure out how to create a query that would list the missing numbers between a high and low number for a field. For example, If I have the recordset below:

1
3
4
6
7
9

I'd like the resulting recordset to be:

2
5
8

Is there a way to achieve this? Thanks, Jason.
Reply With Quote
  #2 (permalink)  
Old 10-06-04, 16:47
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,570
Yes, there are several ways.

What have you covered so far in class?

-PatP
Reply With Quote
  #3 (permalink)  
Old 10-06-04, 17:02
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Question Class?

In Class? I'm not taking a class. I know the programming language fairly well, I just cannot figure this one out. Can you give me a quick example? Thanks, Jason.
Reply With Quote
  #4 (permalink)  
Old 10-06-04, 17:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,570
There are multiple ways to do this. Probably the simplest is to create a "numbers" table with one row for every interesting (possible) value that a number might have. For a two byte integer, this range could be -32768 through 32767. Once you've got the numbers table, you can do a simple exists test, something like:
Code:
SELECT n.val FROM numbers AS n WHERE NOT EXISTS (SELECT * FROM myRecordset AS r WHERE r.val = n.val)
Of course you'd also need to limit the result to just the values of interest in this case (between the Min and Max values already in your recordset).

-PatP
Reply With Quote
  #5 (permalink)  
Old 10-06-04, 17:45
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Exclamation

I had thought of this, the problem is, I cannot create another table. I'm using Foxpro with a proprietary program which will not allow non-program specific tables to be used in conjunction with it's own. I need to find a different way. Thanks for the post though!!
Reply With Quote
  #6 (permalink)  
Old 10-06-04, 17:45
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Exclamation Cannot do that :-(

I had thought of this, the problem is, I cannot create another table. I'm using Foxpro with a proprietary program which will not allow non-program specific tables to be used in conjunction with it's own. I need to find a different way. Thanks for the post though!!
Reply With Quote
  #7 (permalink)  
Old 10-06-04, 17:46
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Exclamation Cannot do that :-(

I had thought of this, the problem is, I cannot create another table. I'm using Foxpro with a proprietary program which will not allow non-program specific tables to be used in conjunction with it's own. I need to find a different way. Thanks for the post though!!
Reply With Quote
  #8 (permalink)  
Old 10-06-04, 17:51
jimithing1980 jimithing1980 is offline
Registered User
 
Join Date: Oct 2004
Location: Pittsburgh, PA
Posts: 10
Exclamation Cannot do that :-(

I had thought of this, the problem is, I cannot create another table. I'm using Foxpro with a proprietary program which will not allow non-program specific tables to be used in conjunction with it's own. I need to find a different way. Thanks for the post though!!
Reply With Quote
  #9 (permalink)  
Old 10-07-04, 10:32
urquel urquel is offline
Registered User
 
Join Date: Aug 2004
Posts: 330
Does Foxpro support recursive queries? If so, you could recursively increment an integer up to some limit and exclude the non-qualifying rows.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On