Results 1 to 7 of 7
  1. #1
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123

    How do i use "not equal to" in a ms query?

    I am trying to use the following simple query to display all employee names that are not in the leave table
    on the selected date from a form and it is coming up blank.

    SELECT tblEmpDetails.Name


    FROM (tblEmpDetails LEFT JOIN tblEmpLeave ON tblEmpDetails.EmpId = tblEmpLeave.EmpID) LEFT JOIN tbl36hrWeekRosters ON tblEmpLeave.Date_ = tbl36hrWeekRosters.Date_
    WHERE (((tblEmpDetails.EmpId)<>[tblEmpLeave].[EmpID]) AND ((tbl36hrWeekRosters.Date_)=[Forms]![Form1]![txtDate]));if I change the <> for = it shows only the employees in the leave table.

    How do i use "not equal to" in a ms query?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Try:

    WHERE [tblEmpLeave].[EmpID] Is Null AND
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123
    When I try this in design view it changes the sql to ="Is Null" and if i put is straight in the SQL it comes back with a syntax error "Missing Operator"

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    I don't know why that would happen. Is Null is perfectly legitimate criteria.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    I don't understand what the 36hrWeekRoster table is. It only seems to have relevant dates on it, so I'm going to ignore my confusion. If there is any employee info linked into it, then your join is wrong. If not, then there is no reason to include it in the JOIN, since it must match the date on the tblEmplLeave table and the date in the form anyway.

    So, in English, what are you trying to do?

    "I want to see all employees who are not in the tblEmpLeave table for the week in the txtDate field."
    Code:
    SELECT 
       TE.Name
    FROM 
       tblEmpDetails AS TE
    WHERE 
       TE.EmpId Not IN 
       ( SELECT TL.EmpID
         FROM tblEmpLeave AS TL
         WHERE TE.Date_ =[Forms]![Form1]![txtDate]);
    This would assume that you have elsewhere constrained the txtDate to be selected from dates in tbl36hrWeekRoster.

  6. #6
    WickidWe is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    123
    Thanks, I finally got it . I just had to change the Where TE.Date_ to TL.Date as only the leave table has a date associated with it.

  7. #7
    Dal Jeanis is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2013
    Location
    Dallas TX
    Posts
    1,742
    Glad you got it worked out.

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

Similar Threads

  1. Export "Query or Report" to a "Delimited Text File"
    By hawzmolly in forum Import/Export Data
    Replies: 3
    Last Post: 08-31-2012, 08:00 AM
  2. Replies: 1
    Last Post: 08-23-2012, 08:32 AM
  3. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  4. Replies: 16
    Last Post: 07-22-2011, 09:23 AM

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