Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sub Queries - Not in compared to Not Exists

Posted on 2014-02-19
2
Medium Priority
?
309 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 2000 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

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

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

927 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