Results 1 to 2 of 2
  1. #1
    dfenton21 is offline Novice
    Windows XP Access 97
    Join Date
    May 2011
    Posts
    6

    WHERE Question

    Hi All,

    I have a simple question (hopefully).

    Code:
    SELECT
    Employees.StaffID, 
    Employees.StaffName, 
    DATEDIFF('d', Employees.StaffStartDate, now()) \ 7 AS ServiceLength, 
    Areas.AreaDescription, 
    
    IIF((SELECT SessionDate FROM Sessions LEFT JOIN Bookings ON Sessions.SessionID = Bookings.SessionID
    WHERE Bookings.StaffID = Employees.StaffID AND Sessions.SessionType = 'Selling Skills' AND Bookings.Attendence = 'Attended') <> Null, TRUE, FALSE) AS SellingSkillsAttendence, 
    
    IIF((SELECT SessionDate FROM Sessions LEFT JOIN Bookings ON Sessions.SessionID = Bookings.SessionID
    WHERE Bookings.StaffID = Employees.StaffID AND Sessions.SessionType = 'Manual Handling' AND Bookings.Attendence = 'Attended') <> Null, TRUE, FALSE) AS ManualHandlingAttendence, 
    
    IIF((SELECT SessionDate FROM Sessions LEFT JOIN Bookings ON Sessions.SessionID = Bookings.SessionID
    WHERE Bookings.StaffID = Employees.StaffID AND Sessions.SessionType = 'EPOS' AND Bookings.Attendence = 'Attended') <> Null, TRUE, FALSE) AS EPOSAttendence, 
    
    IIF((SELECT SessionDate FROM Sessions LEFT JOIN Bookings ON Sessions.SessionID = Bookings.SessionID
    WHERE Bookings.StaffID = Employees.StaffID AND (Sessions.SessionType = 'One Day Induction' OR Sessions.SessionType = 'Induction - Second Day' OR Sessions.SessionType = 'Induction - First Day') AND Bookings.Attendence = 'Attended') <> Null, TRUE, FALSE) AS InductionAttendence, 
    
    IIF((ABS(SellingSkillsAttendence) + ABS(ManualHandlingAttendence) + ABS(EPOSAttendence) + ABS(InductionAttendence)) = 4, TRUE, FALSE) AS InductionProgrammeAttendence
    
    FROM ((Employees LEFT JOIN Departments ON Employees.StaffDept = Departments.DeptID) LEFT JOIN Bookings ON Employees.StaffID = Bookings.StaffID) LEFT JOIN Areas ON Departments.DeptArea = Areas.ID
    The if statement in the code above counts the number of TRUE values in the four fields. If all four fields are TRUE, it returns TRUE otherwise returns FALSE.

    I want to be able to filter the recordset to only show the records where the result of the if statement is FALSE. I assumed this would work after the FROM clause:

    WHERE InductionProgrammeAttendence = FALSE

    But it is asking me to enter a parameter value for InductionProgrammeAttendence.



    Any advice would be appreciated because it seems like a very simple task for Access to do.

    If it makes a difference, I'm using 97

    Thanks.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Because of the order in which the clauses are processed, you can't refer to an alias in the WHERE clause. Because of the number of calculations involved, I'd probably base a second query on this one and use the criteria you intended to use.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

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