SQL Query in Access with YesNo field Returns No Results

17,673

From Microsoft Access Data Types on W3schools, can you try comparing to -1 rather than 1:

A logical field can be displayed as Yes/No, True/False, or On/Off. In code, use the constants True and False (equivalent to -1 and 0). Note: Null values are not allowed in Yes/No fields.

Sorry, don't have a copy of access handy to try this out.

Share:
17,673
KVast
Author by

KVast

Updated on June 27, 2022

Comments

  • KVast
    KVast almost 2 years

    I am learning to use SQL in Access 2013 and things are going well, but I'm having some trouble with one of the objectives of the assignment. First of all, here is the table information that I need to consider:

    Field Name          Data Type
    StudentID           Short Text
    FirstName           ""
    MiddleInitial       ""
    LastName            ""
    DateofBirth         Date/Time
    GradePointAverage   Number
    Major               Short Text
    CreditsEarned       Number
    Probation           Yes/No
    USCitizen           Yes/No
    Class               Short Text
    

    What I need to do is determine the students on Probation who are not US Citizens. Following is my SQL Query Code:

    SELECT   StudentID, LastName, FirstName, Major, Probation, USCitizen 
    FROM Student
    WHERE    Probation = 1
    AND      USCitizen = 0;
    

    There is one record on the Student table that should show up as a result when I run this query, but the query is blank instead, showing the column names but with no rows of data. This is just one aspect of a larger assignment and while I'm not having any difficulty with the other objectives, this one is stumping me. Why is it not returning the one row result? What am I doing wrong here?

  • KVast
    KVast about 10 years
    This worked, thanks a lot for the tip! Sorry about not being able to get a non https image up on my site for the data, to @waka .
  • wwkudu
    wwkudu about 10 years
    Glad to hear it. The mind boggles a little that -1==yes==true.