Solved

Query to return missing values

Posted on 2008-10-28
3
193 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
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
jfmador earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, I was confused when I originally read your response but in the end it was exactly what I needed. Thanks.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now