Solved

Find missing records in one table excluding cancelled items

Posted on 2016-08-25
4
63 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 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 41

Expert Comment

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

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 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