Results 1 to 2 of 2
  1. #1
    zephaneas is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Nov 2008
    Posts
    15

    Problem With WHERE Clause


    I'm trying to add a check for Employees.IsActive to this query

    Code:
    SELECT d.GroupId, 
           Sum(d.cert_complete) AS SumOfcert_complete, 
           Count(d.cert_complete) AS CountOfcert_complete
        FROM (SELECT DISTINCT s.GroupId, e.EmployeeID, IIf(e.Certified Is Null,0,1) AS cert_complete 
        FROM ((Stores AS s 
        INNER JOIN EmployeeStores AS es ON s.StoreId=es.StoreId) 
        INNER JOIN Employees AS e ON es.EmployeeId=e.EmployeeID) 
        INNER JOIN Titles AS t ON e.TitleId=t.TitleId WHERE t.IsManager=True AND e.IsActive=True)  AS d
        GROUP BY d.GroupId
    UNION ALL SELECT 0 as GroupId, 
           Sum(d.cert_complete) AS SumOfcert_complete, 
           Count(d.cert_complete) AS CountOfcert_complete
        FROM (SELECT DISTINCT s.GroupId, e.EmployeeID, IIf(e.Certified Is Null,0,1) AS cert_complete 
        FROM ((Stores AS s 
        INNER JOIN EmployeeStores AS es ON s.StoreId=es.StoreId) 
        INNER JOIN Employees AS e ON es.EmployeeId=e.EmployeeID) 
        INNER JOIN Titles AS t ON e.TitleId=t.TitleId WHERE t.IsManager=True AND e.IsActive=True)  AS d;
    When I run it I still get inactive employees. What am I doing wrong?

  2. #2
    NTC is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2009
    Posts
    2,392
    not sure: looked at code but nothing jumped out at me.

    but consider this. Since your result is to be inactives only. Begin with inactives only. This means rather than begin your Select statement of the table - instead make & save a simple select query of Inactives only...let's call this InactiveQ.

    then begin your Select using the InactiveQ object.

    the query may run faster in eliminating those AND as a by product too....

    might work.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Problem Adding WHERE Clause
    By zephaneas in forum Queries
    Replies: 1
    Last Post: 08-14-2011, 11:26 PM
  2. Using the TOP clause
    By WSlepecki in forum Queries
    Replies: 1
    Last Post: 04-08-2011, 06:59 AM
  3. Where clause
    By Amerigo in forum Queries
    Replies: 2
    Last Post: 03-30-2011, 07:34 AM
  4. IIF clause
    By Peljo in forum Queries
    Replies: 2
    Last Post: 02-05-2008, 11:22 AM
  5. Help on WHERE clause
    By QBCM in forum Programming
    Replies: 1
    Last Post: 12-19-2005, 08:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums