In reply to Leonid Batkhan.

Hi Leonid,
Thank you for your response. The sample answer you wrote above was helpful. However, in my case, the overlapping was a bit different. Say a patient was on three medication: antidepressants, antiepileptic, opioids. He has several fills (several start dates and end dates) for each medication. However, the fills for each medication were not in equal length, making it difficult to examine overlap on three medications. Here is an example:

Medication Start_dt End_dt
CNS_antidepressants 8/29/2013 9/28/2013
CNS_antidepressants 10/3/2013 11/2/2013
CNS_antidepressants 11/4/2013 12/4/2013
CNS_antidepressants 12/7/2013 1/6/2014
CNS_antidepressants 1/22/2014 2/21/2014
CNS_antidepressants 2/16/2014 3/18/2014
CNS_antidepressants 3/19/2014 4/18/2014
CNS_antidepressants 4/16/2014 5/16/2014
CNS_antidepressants 5/7/2014 6/6/2014
CNS_antidepressants 5/11/2014 6/10/2014
CNS_antidepressants 6/4/2014 7/4/2014
CNS_antidepressants 6/29/2014 7/29/2014
CNS_antidepressants 7/27/2014 8/26/2014
CNS_antiepileptic 8/29/2013 9/28/2013
CNS_antiepileptic 10/1/2013 10/31/2013
CNS_antiepileptic 10/26/2013 11/25/2013
CNS_antiepileptic 12/7/2013 1/6/2014
CNS_antiepileptic 1/12/2014 2/11/2014
CNS_antiepileptic 2/16/2014 3/18/2014
CNS_antiepileptic 3/30/2014 4/29/2014
CNS_antiepileptic 5/13/2014 6/12/2014
CNS_antiepileptic 6/7/2014 7/7/2014
CNS_opioid 9/6/2013 10/6/2013
CNS_opioid 10/3/2013 11/2/2013
CNS_opioid 2/7/2014 2/14/2014

As you can see, the first fill of antidepressants and antiepileptic both started on 8/29/2013 and ended on 9/28/2013 (these two were overlapped), and the first opioid started 9/6/2013 and ended 10/6/2013, which overlapped majority of the antidepressants and antiepileptic. Therefore, this patient is flagged as "having at least three medication overlapped".

I guess the coding should have a nested loop to examine each pair of the medications' overlapping. In this case, it should be antidepressants & antiepileptic, antidepressants & opioid, and antiepileptic & opioid. Then if all pairs were flagged, then this patient was flagged.