Assign field value based on date range of another variable in another table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • EORTIZ
    New Member
    • Sep 2007
    • 22

    Assign field value based on date range of another variable in another table

    I have 2 tables:

    Claims table- claim ID, Member_ID, service_from_da te, service_end_dat e.
    Plan table- Member_ID, Plan_ID, Plan_from_date, Plan_end_date. The same member_id can have multiple Plan_ID with different dates.

    I need to assign the Plan_ID to each claim ID. The criteria is that the service_from_da te has to be greater than or equal the Plan_start_date and equal or lower than the Plan_end_date. For claims that are left without the Plan ID, because they are out of range, assign the Plan_ID with Plan_from_date that is lower and closer to the service_from_da te.
  • EORTIZ
    New Member
    • Sep 2007
    • 22

    #2
    Additional explanation of question:

    If service date is between the plan period the statement would be:
    if service_from_da te>=plan_from_d ate and service_from_da te<=plan_end_da te

    But, if the service date is not in the range of the plan dates,

    for example: Service_from_da te=1/15/2008,and let's say that the member has

    Plan_ID=1 for Plan_from_date= 12/1/2007 to Plan_end_date=1 2/31/2007

    Plan_ID=2,Plan_ from_date=1/1/2008 to Plan_end_date=1/31/2008

    Plan_ID=3,Plan_ from_date=2/1/2008 to Plan_end_date=3/31/2008

    I need it assigns Plan_ID=2, which is the plan that was just before the date of service.

    Comment

    Working...