Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Calculate Days between same date field in multiple records, looping for each record

$
0
0

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 :

MemberDrug Code      DateService         Days Between
1A3/1/20120
1A3/27/201227
1A4/21/201226
1A6/15/201256
1F2/25/20120
1F3/20/201225
1F4/17/201229
1F8/1/2012107
5B2/15/20120
5B3/10/201225
5B4/10/201232
5B6/28/201280
5B7/10/201213
5B8/20/201242

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!


Viewing all articles
Browse latest Browse all 24688

Trending Articles



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