Solved

Sub Queries - Not in compared to Not Exists

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

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…

776 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