Solved

Find missing records in one table excluding cancelled items

Posted on 2016-08-25
4
45 Views
Last Modified: 2016-08-25
Hi, I need to find all entries in table Hotelogix which are not existing in table Reservations but excluding cancelled records in Reservations. I have tried the following statement:

SELECT HotelogixReservations.[Group Id], HotelogixReservations.[Guest Name]
FROM HotelogixReservations LEFT JOIN QueryFull ON Ltrim(Rtrim(HotelogixReservations.[Group ID])) = QueryFull.[Group Reservation No]
WHERE (((QueryFull.[Group Reservation No]) Is Null)) OR QueryFull.Cancel=TRUE;

This almost works but gives an error in the case where I have the same reservation in Reservations table twice (once as cancelled and once as an open one). Not sure how to exclude any cancelled records in reservation? Thank you for any help..
0
Comment
Question by:mpim
4 Comments
 
LVL 1

Accepted Solution

by:
rquaglia earned 500 total points
ID: 41770355
Hi!
looking at you question I suggest to try something like:
SELECT HotelogixReservations.[Group Id], HotelogixReservations.[Guest Name]
FROM HotelogixReservations
WHERE Ltrim(Rtrim(HotelogixReservations.[Group ID])) NOT IN (select [Group Reservation No] from QueryFull where Cancel<>TRUE);

Sorry, I can't try this but anyway I hope this helps.
0
 
LVL 40

Expert Comment

by:Sharath
ID: 41770457
Can you provide some sample data and expected result?
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 41770612
The problem with your initial query is the criteria against the "right" table.  The subselect solves that problem.  However, if you are running the query in Access subselects are not well optimized so you could make a query that selects the "right" table and applies the criteria.  Then left join to that query.  Access would then apply the criteria to the "right" table PRIOR to performing the left join and that solves the problem.
1
 

Author Closing Comment

by:mpim
ID: 41770702
Great help! Thank you Michael
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Viewers will learn how the fundamental information of how to create a table.

863 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

19 Experts available now in Live!

Get 1:1 Help Now