Solved

Sub Queries - Not in compared to Not Exists

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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

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.
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

726 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