473,412 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Why do two queries on same table with same criteria return different dynasets?

MLH
Why does this one produce 9 records...
SELECT DISTINCT tblVehicleJobs.VehicleJobID, tblVehicleJobs.Reclaimed,
tblVehicleJobs.VSaleID, tblVehicleJobs.ENF262Written
FROM tblVehicleJobs
WHERE (((tblVehicleJobs.Reclaimed)=No) AND ((tblVehicleJobs.VSaleID)
Is Null) AND ((tblVehicleJobs.ENF262Written)=True));
And this one produces NONE...
SELECT DISTINCT tblVehicleJobs.Reclaimed, tblVehicleJobs.VSaleID,
tblVehicleJobs.ENF262Written
FROM tblVehicleJobs
WHERE (((tblVehicleJobs.Reclaimed)=No) AND ((tblVehicleJobs.VSaleID)
Is Null) AND ((tblVehicleJobs.ENF262Written)=True));
The only difference, AFAIK, is that the first SQL string includes 1
extra output field. I've tested it extensively.
Aug 21 '06 #1
2 1490
Very odd. You would expect the 2nd query to produce at least one record,
even if all the fields were the same at every record.

Firstly, run a compact/repair in case there is a damaged index.

Next possibility is that you are being bitten by a JET bug that handles
Nulls inconsistently, depending on whether the field is uniquely indexed or
not. We know that VSaleID is Null. It looks like a foreign key, so it
probably is indexed (assuming a relation with referential integrity
enforced), but probably not with a Unique index (unless it is a one-to-one
relation.) In any case, you would expect the bug to produce too many rows,
not too few. This article explains the bug:
DISTINCT query handles Nulls inconsistently
at:
http://allenbrowne.com/bug-12.html

The other two fields present in both queries look like yes/no fields. If
tblVehicleJobs is a local JET table (not an attached table from SQL Server
or some other database), then these fields cannot be null, and even if they
were, the criteria would eliminate the nulls.

If VehicleJobID is the primary key field, and this is a simple little Access
table with just 9 records in it, and the compact/repair does not fix the
problem, I am interested in taking a look at this. Create a new database.
Import the table and the 2 queries. Verify the problem still occurs. Zip it,
and email it to the address in the signature below. (You can't click Reply
as the address is munged to avoid spammers.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"MLH" <CR**@NorthState.netwrote in message
news:36********************************@4ax.com...
Why does this one produce 9 records...
SELECT DISTINCT tblVehicleJobs.VehicleJobID,
tblVehicleJobs.Reclaimed,
tblVehicleJobs.VSaleID,
tblVehicleJobs.ENF262Written
FROM tblVehicleJobs
WHERE (((tblVehicleJobs.Reclaimed)=No)
AND ((tblVehicleJobs.VSaleID) Is Null)
AND ((tblVehicleJobs.ENF262Written)=True));
>
And this one produces NONE...
SELECT DISTINCT tblVehicleJobs.Reclaimed,
tblVehicleJobs.VSaleID,
tblVehicleJobs.ENF262Written
FROM tblVehicleJobs
WHERE (((tblVehicleJobs.Reclaimed)=No)
AND ((tblVehicleJobs.VSaleID) Is Null)
AND ((tblVehicleJobs.ENF262Written)=True));
>
The only difference, AFAIK, is that the first SQL string includes 1
extra output field. I've tested it extensively.

Aug 21 '06 #2
MLH
Nope - sorry 'bout that. I'm just dumber 'n
a bag-o-hammers. I had UniqueRecords
property ON and didn't realize it.

So sorry, but thanks much for the offer of
assistance. I notice that you contribute a
lot to this NG. I'm sure there are a lot of
grateful people out there.
Aug 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Metal Dave | last post by:
Hi all, Currently our product has a setup that stores information about transactions in a transaction table. Additionally, certain transactions pertain to specific people, and extra information...
6
by: Brad | last post by:
I have an sql query that has specific criteria (like state='PA' or state = 'NJ'...) and would like to be able to have the user specify the criteria dynamically either through the web or from...
2
by: speedoflight | last post by:
Hi: I'm trying to compare between 2 queries I have run and saved in Access. The DB contains a list of names, emails. Query 1 = Returns all names and emails. I named this query "allemails" ...
3
by: Paolo | last post by:
Friends, My database has 5 different tables (tbl1, tbl2, tlb3, tbl4, and tbl5) with the same fields: ID, SSN, LNAME, FNAME, RECEIVED and CLOSED. The ID is the PK and its autonumber. Obiously...
12
by: Steve Elliott | last post by:
I have a query set up to gather together data between two specified dates. Shown in the query column as: Between #24/09/2004# And #01/10/2004# Is it possible to enter several different date...
3
by: Marcus | last post by:
Wondering if it is possible to use one form to open different queries at different times. As an example, I may have frmViewQueries that opens up when I click a command button on frmMain. So, the...
10
by: john | last post by:
I have a report to print envelopes. The report is based on a query. Now I need to make 10 more queries to make different selections of addresses. Every query has the same output fields as the...
2
by: Dorish3 | last post by:
I want to apologize ahead of time for being a novice with MS Access and VBA. I desperately need help with 2 queries that I am trying to put together. I want to thank anyone that can help me out...
5
by: Brett | last post by:
Hello, Is it possible to have just one criteria and have it apply to a group of queries? I am trying to create a report with the separate results of 4 queries based on a prompt for the user...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.