Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL- find overlapping prescriptions

$
0
0

I have a bunch of patient prescriptions, each having a certain start date and an end date. I would like to find the instances where a patient has been taking more than one drug (at the same time) in the same drug category for more than 2 days. duration  should overlap.

Table structure looks like this:

PatientID  StartDate  EndDate    Drug        DrugCategory
001        1/1/2013  1/5/2013   A           Cat1
001        1/1/2013  1/4/2013   B           Cat1
001        1/10/2013   1/12/2013   C           Cat1
002     .......   ........   ............. .........

In the sample code above, Patient 001 was prescribed 3 drugs in the same category and the first two drug overlapped in duration more than 2 days. So, I would like the query return the first two records.

Hope someone can help. This is using SQL Server 2008 R2 btw.


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>