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?
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 PrewCommented:
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
0

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
0
vbnetcoderAuthor Commented:
It looks like your code is returning values where term and effective date is null
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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


»bp
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.