Where, OR, AND

shafh

Registered User.
Local time
Today, 18:01
Joined
Jun 23, 2003
Messages
27
Hello People,
I am having problems with a WHERE(…OR..AND) that I am trying to implement in a Query. I am trying to write the query so only those records that have been updated in the last 30 days and updated only by John Smith will show up. I’ve tried a lot of combinations but nothing seems to be working. I would really appreciate some help.
Here’s how I’ve written it up right now:

WHERE (((IndustryCurrentEnvironment.UpdateDate)>Date()-30)
OR (((IndustryOutlook.UpdateDate)>Date()-30))
OR (((IndustryPositives.UpdateDate)>Date()-30))
OR (((ParentCreditFundamentals.UpdateDate)>Date()-30))

AND ((IndustryCurrentEnvironment.AnalystName)="John Smith")
AND ((IndustryOutlook.AnalystName)="John Smith")
AND ((IndustryPositives.AnalystName)="John Smith")
AND ((ParentCreditFundamentals.AnalystName)="John Smith")
)

Thanks,
Sam
 
Try this:

WHERE (

(
((IndustryCurrentEnvironment.UpdateDate)>Date()-30)
OR (((IndustryOutlook.UpdateDate)>Date()-30))
OR (((IndustryPositives.UpdateDate)>Date()-30))
OR (((ParentCreditFundamentals.UpdateDate)>Date()-30))
)

AND

(
((IndustryCurrentEnvironment.AnalystName)="John Smith")
AND ((IndustryOutlook.AnalystName)="John Smith")
AND ((IndustryPositives.AnalystName)="John Smith")
AND ((ParentCreditFundamentals.AnalystName)="John Smith")
)

)

But then "John Smith" has to be the value of AnalystName in ALL AnalystName fields. It sounds like that's what you want but I'm not sure.

Hope this helps,
 
Thanks a lot Pat and Peter.
Pat your second suggestion is almost exactly what i want. However it still has one slight problem. What I want to records from within the last 30 days only. Within these records I want records created by John Smith only.
When I use your second query then I get all records in the last 30 days however the problem is I also get (for example) where the IndustryCurrentEnvironment was created by John Smith but the IndustryOutlook was updated by Jane Doe in the same row.
Is there a way to get just the stuff that John Smith did in the last 30 days and perhaps have the fields left blank for the rest of the row if Jane Doe did something else on that date.
Thanks
 
is it possible

Can one have a

SELECT
FROM
WHERE
statement followed by a
SELECT
FROM
WHERE
followed by a
UNION SELECT
FROM
WHERE

to union the second and third SELECT's but not the first SELECTFROMWHERE statement.
 
Thanks

Thanks a lot Pat and Peter. I really appreciate both your help. I was able to figure it out thanks to your help and advice. Have a great weekend!
 

Users who are viewing this thread

Back
Top Bottom