?
Solved

Find missing records in one table excluding cancelled items

Posted on 2016-08-25
4
Medium Priority
?
68 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
[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
4 Comments
 
LVL 1

Accepted Solution

by:
rquaglia earned 2000 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 41

Expert Comment

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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.
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…
Suggested Courses

762 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