and / or logic in where clause

how would I update the code to grab: Effective or Term within the last 7 days OR last update within last 7 days with effective or term date prior to the last 7 days?

WHERE ek.OrderId = 'rty5465464'

      AND (
              ek.termdate
      BETWEEN GETDATE() - 7 AND GETDATE()
              OR ek.effdate
      BETWEEN GETDATE() - 7 AND GETDATE()
	  OR
	          ek.lastupdate
      BETWEEN GETDATE() - 7 AND GETDATE()

Open in new window

vbnetcoderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewIT / Software Engineering ConsultantCommented:
Sounds like this would be it.  Be aware though that BETWEEN can be tricky, unless you know your date fields don't have time info in them?

WHERE  ek.orderid = 'rty5465464' 
       AND ( ( ek.termdate BETWEEN Getdate() - 7 AND Getdate() 
                OR ek.effdate BETWEEN Getdate() - 7 AND Getdate() ) 
              OR ( ek.lastupdate BETWEEN Getdate() - 7 AND Getdate() 
                   AND ( ek.termdate < Getdate() - 7 
                          OR ek.effdate < Getdate() - 7) ) ) 

Open in new window


»bp

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vbnetcoderAuthor Commented:
There are dates that look like this:
2017-11-01 00:00:00
vbnetcoderAuthor Commented:
It looks like your code is returning values where term and effective date is null
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

vbnetcoderAuthor Commented:
actually not. I was wrong about the nulls
Pawan KumarDatabase ExpertCommented:
can you pls provide few input rows and the expected output.
vbnetcoderAuthor Commented:
ty
Bill PrewIT / Software Engineering ConsultantCommented:
Welcome.


»bp
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
T-SQL

From novice to tech pro — start learning today.