Mismatch query not working. Not sure what I did wrong.

In my query, I have created two CTE's. One pulls in the records of all people who are assigned to an audience. The other pulls in all people who are assigned to the same audience AND completed a certain course.
What I wanted to do from there, was to do a mismatch query, not to find the PEOPLE, but just the departments that were represented in the audience, but had no people in the list of those who completed the course. (In other words, say the HR Department had
three people in the audience... two completed the course, one did not. The HR Department should NOT show up in my mismatch query because some of their people completed the course. Then, say the IT Department had five people in the audience, and none of them
have completed the course. The IT Department SHOULD show up in my mismatch query. For this case, I don't care about the people who didn't complete it, just the departments where nobody did yet.)
I thought I was doing the mismatch query correctly, but I guess I must not. I will share the relevant parts of my query below (there is more to my query, but I don't think you necessarily need to see it to assist with this particular problem). (Side note:
Yes, I know the way I am doing the fiscal calendar is not ideal, but I've looked up other ways to do it, and do not understand it. Given time, I can break it down and understand it, but I am in a rush to finish this report.)
gm101certtbl
AS
select
dimUser.EmpFK MeasureEmpFK,
RIGHT(OrgCode2, LEN(OrgCode2) - 2) MeasurePC,
audusersName MeasureAudName,
dimActivity.ActivityName MeasureActName,
dimActivity.Code MeasureActCode,
CASE
WHEN OrgCode2 LIKE 'US%' then 'US'
WHEN OrgCode2 LIKE 'CA%' then 'CA' END
CountryCode,
'ACTUALS_GM101' SOURCESYSTEMID,
Null CURRENCYCODE,
'GM101CERT' MEASUREID,
Null MEASUREDOLLARS,
CASE
WHEN GETDATE() Between '20131001 00:00:00' AND '20140930 11:59:59' THEN '2014'
WHEN GETDATE() Between '20141001 00:00:00' AND '20150930 11:59:59' THEN '2015'
WHEN GETDATE() Between '20151001 00:00:00' AND '20160930 11:59:59' THEN '2016'
WHEN GETDATE() Between '20161001 00:00:00' AND '20170930 11:59:59' THEN '2017' END
FiscalYear,
CASE
WHEN MONTH(GETDATE()) = '10' THEN '1'
WHEN MONTH(GETDATE()) = '11' THEN '2'
WHEN MONTH(GETDATE()) = '12' THEN '3'
WHEN MONTH(GETDATE()) = '1' THEN '4'
WHEN MONTH(GETDATE()) = '2' THEN '5'
WHEN MONTH(GETDATE()) = '3' THEN '6'
WHEN MONTH(GETDATE()) = '4' THEN '7'
WHEN MONTH(GETDATE()) = '5' THEN '8'
WHEN MONTH(GETDATE()) = '6' THEN '9'
WHEN MONTH(GETDATE()) = '7' THEN '10'
WHEN MONTH(GETDATE()) = '8' THEN '11'
WHEN MONTH(GETDATE()) = '9' THEN '12' END
FiscalMonthNbr
from
dimUser INNER JOIN
audusers ON audusers.DataSetUsers_EmpFK = dimUser.EmpFK INNER JOIN
Org ON dimUser.PrimaryDomFK = Org.Org_PK INNER JOIN
factUserRequiredActivity ON factUserRequiredActivity.UserID = dimUser.ID INNER JOIN
dimActivity ON dimActivity.ID = factUserRequiredActivity.ActivityID INNER JOIN
dimRequirementStatus ON factUserRequiredActivity.ReqStatusID = dimRequirementStatus.ID LEFT OUTER JOIN
UsrOrgs ON dimUser.ID = UsrOrgs.UserID LEFT OUTER JOIN
UsrDoms ON dimUser.ID = UsrDoms.UserID
WHERE
dimActivity.ActivityName = 'GM101 Program Completion'
AND
dimRequirementStatus.name = 'Satisfied'
AND
(audusersName = @audparam)
gm101availtbl
AS
select
dimUser.EmpFK MeasureEmpFK,
RIGHT(OrgCode2, LEN(OrgCode2) - 2) MeasurePC,
audusersName MeasureAudName,
Null MeasureActName,
Null MeasureActCode,
CASE
WHEN OrgCode2 LIKE 'US%' then 'US'
WHEN OrgCode2 LIKE 'CA%' then 'CA' END
CountryCode,
'ACTUALS_GM101' SOURCESYSTEMID,
Null CURRENCYCODE,
'GM101AVAIL' MEASUREID,
Null MEASUREDOLLARS,
CASE
WHEN GETDATE() Between '20131001 00:00:00' AND '20140930 11:59:59' THEN '2014'
WHEN GETDATE() Between '20141001 00:00:00' AND '20150930 11:59:59' THEN '2015'
WHEN GETDATE() Between '20151001 00:00:00' AND '20160930 11:59:59' THEN '2016'
WHEN GETDATE() Between '20161001 00:00:00' AND '20170930 11:59:59' THEN '2017' END
FiscalYear,
CASE
WHEN MONTH(GETDATE()) = '10' THEN '1'
WHEN MONTH(GETDATE()) = '11' THEN '2'
WHEN MONTH(GETDATE()) = '12' THEN '3'
WHEN MONTH(GETDATE()) = '1' THEN '4'
WHEN MONTH(GETDATE()) = '2' THEN '5'
WHEN MONTH(GETDATE()) = '3' THEN '6'
WHEN MONTH(GETDATE()) = '4' THEN '7'
WHEN MONTH(GETDATE()) = '5' THEN '8'
WHEN MONTH(GETDATE()) = '6' THEN '9'
WHEN MONTH(GETDATE()) = '7' THEN '10'
WHEN MONTH(GETDATE()) = '8' THEN '11'
WHEN MONTH(GETDATE()) = '9' THEN '12' END
FiscalMonthNbr
from
dimUser INNER JOIN
audusers ON audusers.DataSetUsers_EmpFK = dimUser.EmpFK INNER JOIN
Org ON dimUser.PrimaryDomFK = Org.Org_PK LEFT OUTER JOIN
UsrOrgs ON dimUser.ID = UsrOrgs.UserID LEFT OUTER JOIN
UsrDoms ON dimUser.ID = UsrDoms.UserID
WHERE
audusersName = @audparam
missingPC
AS
select distinct
NULL MeasureEmpFK,
gm101availtbl.MeasurePC,
gm101availtbl.MeasureAudName,
gm101availtbl.MeasureActName,
gm101availtbl.MeasureActCode,
gm101availtbl.CountryCode,
gm101availtbl.SOURCESYSTEMID,
gm101availtbl.CURRENCYCODE,
'GM101CERT' MEASUREID,
gm101availtbl.MEASUREDOLLARS,
gm101availtbl.FiscalYear,
gm101availtbl.FiscalMonthNbr
from
gm101availtbl LEFT OUTER JOIN
gm101certtbl on gm101certtbl.MeasurePC = gm101availtbl.MeasurePC
WHERE gm101certtbl.MeasurePC IS NULL
If anybody can help, I would greatly appreciate it. I'm trying to do this so I can pull these records into a final table to count the records from the other two, but then include these as a 0 count where these departments have nobody certified.
To test if this was working, I created a query using this Mismatch query instead as the main query. Instead, it seemed to give me the exact opposite. It seemed to be giving me all of the Departments (MeasurePC) where the records were represented.

Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
This is minimal polite behavior on SQL forums. We have no sample data, so we cannot even guess. 
>> In my query, I have created two CTE's. One pulls in the records [sic] of all people who are assigned to an audience. The other pulls in all people who are assigned to the same audience AND completed a certain course. <<
Please, please learn the basic terms. Rows are not records. And THEN learn what “redundancy” means so you will not write two CTEs in the future. 
>> What I wanted to do from there, was to do a mismatch query, not to find the PEOPLE, but just the departments that were represented in the audience, but had no people in the list of those who completed the course. (In other words, say the HR Department
had three people in the audience... two completed the course, one did not. The HR Department should NOT show up in my mismatch query because some of their people completed the course. THEN, say the IT Department had five people in the audience, and none of
them have completed the course. The IT Department SHOULD show up in my mismatch query. For this case, I don't care about the people who didn't complete it, just the departments where nobody did yet.) <<
This is a Relational Division. It is one of Dr. Codd's original 8 operations. 
We do not use the Sybase CURRENT_TIMESTAMP any more. We have DATE data types tody, rtoo. We never tibble in good code; it is a design flaw that used meta-data affixes like “tbl” in schema object _names, PK in column _names, etc. We do not have repeated groups
like “org_code_2”; we do not use arrays in RDBMS. Why is your data so screwed up you have use 
CASE 
WHEN org_code2 LIKE 'US%' THEN 'US'
WHEN org_code2 LIKE 'CA%' THEN 'CA' END 
to clean it up in a query; the DDL should have prevented this problem. 
Why are you doing calendar computing in your query? Where is the Calendar table? 
“Users.id = UsrOrgs.user_id” says that you have magic, generic “id” that can change its name from table to table. Likewise, a generic, magic “code”, etc. What might be even worse is that totally different data elements have the same name! “Automobiles, squids
and Lady Gaga” programming is not RDBMS. 
You have never heard of ISO-11179 and data modeling? 
Here is a skeleton for fiscal calendar table to replace your current row by row temporal math: 
CREATE TABLE Calendar 
(cal_date DATE NOT NULL PRIMARY KEY, 
 fiscal_month CHAR(10) NOT NULL,
INSERT INTO  Calendar
VALUES 
('2014-10-01', '2015-01-00', ..), 
('2014-09-30', '2015-12-00', ..), 
You can use a spread sheet and a text edit to fill in the table for 50 or 100 years. 
I like the MySQL convention of using double zeroes for months and years, That is 'yyyy-mm-00' for a month within a year and 'yyyy-00-00' for the whole year. The advantages are that it will sort with the ISO-8601 data format required by Standard SQL and it is
language independent. The pattern for validation is '[12][0-9][0-9][0-9]-00-00' and '[12][0-9][0-9][0-9]-[01][0-9]-00'
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

Maybe you are looking for

  • XSQL LookUpTable

    I am trying to use an Oracle XSQL query as a lookup table in my XSLT. I have figured out how to do this with Static data but am having slight difficulty using the XSQL. The easiest solution (I think) would be to return the resultset as a Namespace su

  • [solved] Gnome-do can't open home folder

    I've been using gnome-do for a while now and like it, but I can't get it to open my home folder.  This is with the docky theme.  If I try to use it to open my home folder. What I mean is type super-space to bring up the text input box and then type "

  • JUST UPGRADED TO FIREFOX 4 AND NOW JAVASCRIPT NOT ENABLED EVEN THOUGH IT SAYS IT IS

    when I enter data on a website I get this response...previous to firefox upgrade it was ok We have detected that your browser does not support JavaScript or it is disabled. This site requires JavaScript to be enabled to function correctly. If you con

  • NPiV and non-local zones

    In this PDF from emulex, it talks about how Emulex HBAs can be used to configure NPiV WWNs for Solaris non-global zones. http://www.emulex.com/artifacts/ddf25e8c-1d8e-456f-96ff-21a5353a9d59/solaris10-6.pdf I have yet to find any detailed information

  • How to set 32bit ODBC connection to the application in 64 bit OS

    hi, I have BO installed in 64 Bit windows OS and the mysql data server in 32bit windows OS. i created DNS on the server for the data server. when i click on test connection, I'm getting a message DBD:[Microsoft][ODBC Driver Manager] Data source name