Be patient as I am a newbie to Sql Server (using 2008 R2) and SSIS. I have looked at multiple solutions in this and many other forums before submitting the question.
I am looking at records to identify the number of days between two dates. We review drug information. A member uses drug A (Code identifies this called GPI) and has refills throughout time. The goal is to calculate the days between Refill 1 and refill 2, then refill 2 to refill 3, etc. When that member record set is complete, we move to the next member record set.
The basic data would be as follows. Each record shown below would be a separate record in a single table :
Member | Drug Code | DateService | Days Between |
1 | A | 3/1/2012 | 0 |
1 | A | 3/27/2012 | 27 |
1 | A | 4/21/2012 | 26 |
1 | A | 6/15/2012 | 56 |
1 | F | 2/25/2012 | 0 |
1 | F | 3/20/2012 | 25 |
1 | F | 4/17/2012 | 29 |
1 | F | 8/1/2012 | 107 |
5 | B | 2/15/2012 | 0 |
5 | B | 3/10/2012 | 25 |
5 | B | 4/10/2012 | 32 |
5 | B | 6/28/2012 | 80 |
5 | B | 7/10/2012 | 13 |
5 | B | 8/20/2012 | 42 |
The days between is the value I am looking to calculate. The First record for the grouping of Member and Drug Code will be zero ( 0 ) as there is no preceding date to calculate against. The process would then loop through the records at the grouping (Member and Drug Code) until those records are calculated. It would then move on to the next group of Member/Drug records.
Any assistance would be greatly appreciated. Any clarification I can provide, I would be more than happpy too. Thank you in advance!