Search code examples
sqlsql-server-ce

Query based on more than 1 field


not sure how to title this but here is my scenario

working on Webmatrix, built in sqlCE DB.

Have a table with multiple bit fields (3 fields)

what i need is to search for all records but skip those where any one of these three bit fields is False

my query looks like this

Select * From Tr where Tr.ClID=28 and (VApproved<>'False' or PApproved<>'False' or CApproved<>'False')

Now if i search for ClID=28 i get 7 records and with the above query also get 7 records. Se basically the second part of the where condition is not working.

Appreciate your help and assistance.

Thanks,

Addition Data Looks like this

ClID    VApproved    PApproved    CApproved
****    *********    *********    *********
28      True         True         True
28      True         True         True
28      NULL         True         True
28      NULL         True         True
28      NULL         True         True
28      NULL         True         True
28      NULL         False        True

Solution

  • If you need to skip any with False value, then you it's just your condition that isn't correct, it should be:

    Select * From Tr where Tr.ClID=28 and VApproved<>'False' and PApproved<>'False' and CApproved<>'False'

    i.e. all of them must not be false, so we use AND not OR. And considering your NULL requirement it should be like this:

    Select * From Tr where Tr.ClID=28 and (VApproved=1 OR VApproved IS NULL) and (PApproved=1 OR PApproved IS NULL) and (CApproved=1 OR PApproved IS NULL)