How to write this logic?

Hi I have two sets of dates as the following scenarios:

   Basically, i want to show the criteria under scenario, where the payment_start_dt or payment_end_dt fall between eli.start_dt and eli.end_dt. If the eli.end_dt is null, then the eli.end_dt is current date.

  I know this is simple, but not able to code it properly.
Please help.

SCENARIO#1:

ELI.START_DT = 1/3/2009
ELI.END_DT IS 3/31/2009
ELI.CRITERIA = INCOMPLETE

PAYMENT_START_DT IS 2/9/2009
PAYMENT_END_DT IS 2/28/2009

OUTPUT : CRITERIA = INCOMPLETE

SCENARIO#2:

ELI.START_DT = 2/3/2009
ELI.END_DT IS NULL
ELI.CRITERIA = PENDING

PAYMENT_START_DT IS 2/9/2009
PAYMENT_END_DT IS 2/28/2009

OUTPUT : CRITERIA = PENDING

pvsbandiAsked:
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.

Kent OlsenDBACommented:

Piece of cake.  :)

>> where the payment_start_dt or payment_end_dt fall between eli.start_dt and eli.end_dt. If the eli.end_dt is null, then the eli.end_dt is current date.



Kent

SELECT ...
WHERE (payment_start_dt between eli.start_dt and coalesce (eli.end_dt, current date))
  OR (payment_end_dt between eli.start_dt and coalesce (eli.end_dt, current date))

Open in new window

pvsbandiAuthor Commented:
sorry, forgot another scenario.

SCENARIO#2:

ELI.START_DT = 2/10/2009
ELI.END_DT IS 2/11/2009
ELI.CRITERIA = PENDING

PAYMENT_START_DT IS 2/1/2009
PAYMENT_END_DT IS 2/28/2009

OUTPUT : CRITERIA = PENDING

momi_sabagCommented:
select case when payment_start_dt between eli.start_dt and coalesce(eli.end_dt, current date)
              or payment_end_dt between eli.start_dt and  coalesce(eli.end_dt, current date) then 'INCOMPLETE'
    else 'PENDING'
   end
from your_table


i hope i understand your logic, because you did not explain it very well
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

pvsbandiAuthor Commented:
Thanks for the quick turnaround..

        Both of your logic makes sense to me, until i added another scenario.
         Can you also please consider in the code?
       Thanks again for the help!
pvsbandiAuthor Commented:
To explain better, i think i mean, whenever the month and year of eli.startdt/eli.end_dt overlaps with the payment_start/end dates, then the criteria should be picked.
Kent OlsenDBACommented:

I think that momi's CASE logic fits better. With that in mind.....


select 
  case when payment_start_dt between eli.start_dt and coalesce(eli.end_dt, current date)
         or payment_end_dt between eli.start_dt and  coalesce(eli.end_dt, current date) 
         or (payment_start_dt < eli.start_dt and payment_end_dt > eli.end_dt) then 'INCOMPLETE'
    else 'PENDING'
   end
from your_table

Open in new window

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
pvsbandiAuthor Commented:
Thank much! Greatly appreciate!
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
DB2

From novice to tech pro — start learning today.