Solved

Sub Queries - Not in compared to Not Exists

Posted on 2014-02-19
2
302 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

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

867 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