Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Query to return missing values

Posted on 2008-10-28
3
Medium Priority
?
200 Views
Last Modified: 2012-05-05
I am creating a database to track verifications on welds. The user is free to enter welds in whatever order they would like as welds are not always verified in order. I would like a query that would show all welds less than the greatest weld # that do not have a corresponding record in the database so that they can be listed for the user when they close the database to remind them that they still need to enter them. So far I have the attached code below however if I have records 1,2,3,9, and 10 it will only tell me that I am missing 4 and 11 instead of 4,5,6,7,and 8.
SELECT [Weld #]+1
FROM tblWeldLog AS T1
WHERE (((Exists (select * from tblWeldLog T2 where T2.[Weld #] = T1.[Weld #] + 1))=False));

Open in new window

0
Comment
Question by:FINGERHUT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 1000 total points
ID: 22828597
There is no way to do that using a single table in a single query, because your database don't know which weld need to be done, also it cannot create rows that doesn't exists in your database. For example you have the tblWeldLog with two distinct entries 1 and 100, you want to get a dataset of 98rows.

To do it you need to have a table listing the welds to do like a Job table with column JobID, WeldID
where you can find your 10 rows representing the weld to do (from 1 to 10)

Then you will be able to do a query on your two table

SELECT * FROM tblJob j LEFT JOIN tblWeldLog w on j.WeldID = w.WeldID where w.WeldID is null

it will return you the job that don't have any log.

0
 
LVL 1

Author Comment

by:FINGERHUT
ID: 22831248
Could I perhaps create a table that just holds the values 1 - 9999 and create a query that finds all records that do not exist in the tblWeldLog but exist in NewTable and is not greater than the MAX value in tblWeldLog? If that could work could you help me write that query?

Thanks,

- FINGERHUT
0
 
LVL 1

Author Closing Comment

by:FINGERHUT
ID: 31511051
Sorry, I was confused when I originally read your response but in the end it was exactly what I needed. Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question