We help IT Professionals succeed at work.
Get Started

Picking the correct field value based on matching criteria range

GPSPOW asked
Last Modified: 2015-03-04
I would like to write a SQL statement that obtains a field value from a table with effective date ranges based on the value of another data field

An example is:
DRG Table:
Diagnosis Code            Length of Stay         EffectiveDate
700                                    5.7                              10/1/2013
700                                    5.9                               10/1/2014


DRG                    Admission Date                   Length Of Stay
700                              8/31/14                                5.7
700                            11/1/14                                  5.9

In this example, the admission date 8/31/14 is between 10/1/13 and 9/30/14 so the Length of Stay would be 5.7.  While the other admission had a date after 10/1/14 and before 9/30/15, has a Length Of Stay of 5.9.

I do I write the code to evaluate this from the two tables:  DRG and Admissions?


Watch Question
EE Topic Advisor
Most Valuable Expert 2014
Awarded 2013
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE