Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERE clause w/ AND & OR 2

Status
Not open for further replies.

SBelyea

Technical User
Joined
May 29, 2008
Messages
46
Location
US
I'm currently working on a query which is being used to return records which are overdue, based on the calculation of:
Code:
 ((([InspRequiredOn]+(([PropInspInterval]*365)+1))<(Date())))
In order to show these overdue records, my WHERE clause looks like this:
Code:
WHERE ((([InspRequiredOn]+(([PropInspInterval]*365)+1))<(Date()))) And ((([tblProperty.PropInspBegun])=-1) And (([tblInspection].[InspRequiredOn]) Is Null))
Here is my problem: I would like to display only records that have their InspRequiredOn < Date() OR where InspRequiredOn Is Null - but for either case, the record must also have PropInspBegun = -1 (PropInspBegun is a yes/no box).

Anyone have an idea of how to make this work? Below is the SQL in its current form:

Code:
SELECT [tblOwner].[OwnersBusiness], [InspRequiredOn]+(([PropInspInterval]*365)+1) AS Expr1, [tblOwner].[AutoIDOwner], [tblOwner].[SiteAccepted], [tblOwner].[OwnersFirstName], [tblOwner].[OwnersLastName], [tblOwner].[OwnersStreetAdd], [tblOwner].[OwnersCity], [tblOwner].[OwnersState], [tblOwner].[OwnersZipCode], [tblOwner].[OwnersPhoneNumber], [tblOwner].[OwnersEmail], [tblOwner].[MntAgrSigned], [tblOwner].[MntAgrDate], [tblOwner].[MntAgrLoc], [tblOwner].[OwnerNotes], [tblProperty].[PropInspBegun]
FROM (tblOwner INNER JOIN tblProperty ON [tblOwner].[AutoIDOwner]=[tblProperty].[AutoIDOwner]) INNER JOIN tblInspection ON [tblProperty].[AutoIDProperty]=[tblInspection].[AutoIDProperty]
WHERE ((([InspRequiredOn]+(([PropInspInterval]*365)+1))<(Date()))) And ((([tblProperty.PropInspBegun])=-1) And (([tblInspection].[InspRequiredOn]) Is Null))
ORDER BY [InspRequiredOn]+(([PropInspInterval]*365)+1);
 
maybe:

Code:
SELECT O.[OwnersBusiness], [InspRequiredOn]+(([PropInspInterval]*365)+1) AS Expr1, O.[AutoIDOwner], O.[SiteAccepted], O.[OwnersFirstName], O.[OwnersLastName], O.[OwnersStreetAdd], O.[OwnersCity], O.[OwnersState], O.[OwnersZipCode], O.[OwnersPhoneNumber], O.[OwnersEmail], O.[MntAgrSigned], O.[MntAgrDate], O.[MntAgrLoc], O.[OwnerNotes], P.[PropInspBegun]
FROM (tblOwner O INNER JOIN tblProperty P ON O.[AutoIDOwner]=P.[AutoIDOwner]) INNER JOIN tblInspection I ON P.[AutoIDProperty]=I.[AutoIDProperty]
WHERE [P.PropInspBegun]=-1 AND (([InspRequiredOn] + ([PropInspInterval]*365)+1) < Date()) OR ([tblInspection].[InspRequiredOn] Is Null))
ORDER BY [InspRequiredOn]+(([PropInspInterval]*365)+1);

Leslie

Have you met Hardy Heron?
 
Code:
WHERE tblProperty.PropInspBegun=-1 AND (([InspRequiredOn]+[PropInspInterval]*365+1)<Date() OR [InspRequiredOn] Is Null)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks everyone! I discovered quite the gem - that I can use parentheses around an OR argument (I'm very new to SQL). Thanks for the assistance - stars all around!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top