Solved

Sub Queries - Not in compared to Not Exists

Posted on 2014-02-19
2
301 Views
Last Modified: 2014-02-19
I need to create a query that looks at the values in 1 table and return all records that are not included in the table2

SELECT "CO" & [Con] AS ContractNumber, tblAgentProd.Year, tblAgentProd.Quarter, tblAgentProd.Curr, Sum(tblAgentProd.TotalNetTotalUS) AS TotalNetTotalUS, Sum(tblAgentProd.TotalNetTotal) AS TotalNetTotal, Sum(tblAgentProd.TotalQualifiedTotal) AS TotalQualifiedTotal, Sum(tblAgentProd.TotalQualifiedTotalUS) AS TotalQualifiedTotalUS, Sum(tblAgentProd.AlaskaNetTotalUS) AS AlaskaNetTotalUS, Sum(tblAgentProd.AlaskaNetTotal) AS AlaskaNetTotal, Sum(tblAgentProd.AlaskaQualifiedTotal) AS AlaskaQualifiedTotal, Sum(tblAgentProd.AlaskaQualifiedTotalUS) AS AlaskaQualifiedTotalUS, Sum(tblAgentProd.TourNetTotalUS) AS TourNetTotalUS, Sum(tblAgentProd.TourNetTotal) AS TourNetTotal, Sum(tblAgentProd.TourQualifiedTotal) AS TourQualifiedTotal, Sum(tblAgentProd.TourQualifiedTotalUS) AS TourQualifiedTotalUS, Sum(tblAgentProd.OtherNetTotalUS) AS OtherNetTotalUS, Sum(tblAgentProd.OtherNetTotal) AS OtherNetTotal, Sum(tblAgentProd.OtherQualifiedTotal) AS OtherQualifiedTotal, Sum(tblAgentProd.OtherQualifiedTotalUS) AS OtherQualifiedTotalUS, Sum(tblAgentProd.YENetUS) AS YENetUS, Sum(tblAgentProd.YENet) AS YENet
FROM tblAgentProd
GROUP BY "CO" & [Con], tblAgentProd.Year, tblAgentProd.Quarter, tblAgentProd.Curr, tblAgentProd.Con

HAVING (((tblAgentProd.Year)=Year(Date())) AND

 ((tblAgentProd.Quarter)<>("Select Quarter from [tblSummaryQuartersFrozen]")) AND
 ((tblAgentProd.Con)<>"NON-AFFL" 
And (tblAgentProd.Con)<>"@DEFAULT"));

Open in new window


In this case I want to return all records from the TBLsummary where Quarters not equal to the value of quarters in tblsummaryQuartersFrozedn.

What am I missing?  I tried Not In (Select... and Not Exists (Select... also <>, none of these
limit the list of records where Quarter 1 exists in the Frozen table.

Thanks,

K
0
Comment
Question by:Karen Schaefer
2 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 39871758
select T.*
from TBLsummary  as T
left join tblSummaryQuartersFrozen  as Q
On T.[Quarter]=Q.[Quarter]
Where Q.[Quarter] is null
0
 

Author Closing Comment

by:Karen Schaefer
ID: 39871888
Thanks Rey, that did the trick.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
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…

760 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

20 Experts available now in Live!

Get 1:1 Help Now