Problem with "and" & "or"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have this SQL in the query, the problem is I want to run the data by the
dates specficied. However, every date shows up anybody know why?

SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE (((RISK1.DOCCRS) Between #7/1/2005# And #6/30/2006#) AND
((RISK1.review)=-1)) OR (((RISK1.[PRE-LIT])=-1)) OR (((RISK1.[Near Miss
?])=-1));
 
SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE (RISK1.DOCCRS Between #7/1/2005# And #6/30/2006# AND
RISK1.review=-1) OR RISK1.[PRE-LIT]=-1 OR RISK1.[Near Miss ?]=-1;

Well, if you get rid of the superfluous parenthases, you have the above.
Which means you are only checking RISK1.review=-1 for those dates. You are
checking PRE-LIT and [Near Miss ?] for all dates. Change it to this:

SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE RISK1.DOCCRS Between #7/1/2005# And #6/30/2006# AND
(RISK1.review=-1 OR RISK1.[PRE-LIT]=-1 OR RISK1.[Near Miss ?]=-1);


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
Thank you

Roger Carlson said:
SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE (RISK1.DOCCRS Between #7/1/2005# And #6/30/2006# AND
RISK1.review=-1) OR RISK1.[PRE-LIT]=-1 OR RISK1.[Near Miss ?]=-1;

Well, if you get rid of the superfluous parenthases, you have the above.
Which means you are only checking RISK1.review=-1 for those dates. You are
checking PRE-LIT and [Near Miss ?] for all dates. Change it to this:

SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE RISK1.DOCCRS Between #7/1/2005# And #6/30/2006# AND
(RISK1.review=-1 OR RISK1.[PRE-LIT]=-1 OR RISK1.[Near Miss ?]=-1);


--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L



bladelock said:
I have this SQL in the query, the problem is I want to run the data by the
dates specficied. However, every date shows up anybody know why?

SELECT RISK1.DOCCRS, RISK1.review, RISK1.[PRE-LIT], RISK1.[Near Miss ?]
FROM RISK1
WHERE (((RISK1.DOCCRS) Between #7/1/2005# And #6/30/2006#) AND
((RISK1.review)=-1)) OR (((RISK1.[PRE-LIT])=-1)) OR (((RISK1.[Near Miss
?])=-1));
 
Back
Top