I have 2 tables which I need to join. One holds account data based on policy number which is updated each month when a policy makes a payment the other has the policy history.
POLICYHISTORY
strPolicyNumber strCoverChoice datUpdateTimeSt amp
336392BRPA P 01/08/2009
336392BRPA PX 27/05/2010
336392BRPA P5 12/07/2010
ACCOUNTS
Policy_Id MonthEndDate PremiumPaid
336392BRPA 31/08/2009 £7.98
336392BRPA 31/08/2009 £7.98
336392BRPA 30/09/2009 £7.98
336392BRPA 31/10/2009 £7.98
336392BRPA 30/11/2009 £7.98
336392BRPA 31/12/2009 £7.98
336392BRPA 31/01/2010 £7.98
336392BRPA 28/02/2010 £7.98
336392BRPA 31/03/2010 £7.98
336392BRPA 30/04/2010 £7.98
336392BRPA 31/05/2010 £7.98
336392BRPA 30/06/2010 £7.98
336392BRPA 31/07/2010 £7.98
336392BRPA 31/08/2010 £0.78
336392BRPA 31/08/2010 £0.00
336392BRPA 31/08/2010 £8.76
336392BRPA 10/09/2010 £8.76
I need to add the cover choice from the policy table for each entry in the Accounts table. The problem is that I need to get it to add the cover choice based on the month end date to give something that looks like this:
Policy_Id MonthEndDate PremiumPaid strCoverChoice
336392BRPA 31/08/2009 £7.98 P
336392BRPA 31/08/2009 £7.98 P
336392BRPA 30/09/2009 £7.98 P
336392BRPA 31/10/2009 £7.98 P
336392BRPA 30/11/2009 £7.98 P
336392BRPA 31/12/2009 £7.98 P
336392BRPA 31/01/2010 £7.98 P
336392BRPA 28/02/2010 £7.98 P
336392BRPA 31/03/2010 £7.98 P
336392BRPA 30/04/2010 £7.98 P
336392BRPA 31/05/2010 £7.98 PX
336392BRPA 30/06/2010 £7.98 PX
336392BRPA 31/07/2010 £7.98 P5
336392BRPA 31/08/2010 £0.78 P5
336392BRPA 31/08/2010 £0.00 P5
336392BRPA 31/08/2010 £8.76 P5
336392BRPA 10/09/2010 £8.76 P5
The cover choice changed on the 27/05/2010 and 12/07/2010 so all entries in the accounts table with a month end dates after these dates will have the corresponding cover choice. This is the first time I've used a forum like this so apologies if I've not followed the correct posting convention bu any help would be appreciated as I'm stumped..
POLICYHISTORY
strPolicyNumber strCoverChoice datUpdateTimeSt amp
336392BRPA P 01/08/2009
336392BRPA PX 27/05/2010
336392BRPA P5 12/07/2010
ACCOUNTS
Policy_Id MonthEndDate PremiumPaid
336392BRPA 31/08/2009 £7.98
336392BRPA 31/08/2009 £7.98
336392BRPA 30/09/2009 £7.98
336392BRPA 31/10/2009 £7.98
336392BRPA 30/11/2009 £7.98
336392BRPA 31/12/2009 £7.98
336392BRPA 31/01/2010 £7.98
336392BRPA 28/02/2010 £7.98
336392BRPA 31/03/2010 £7.98
336392BRPA 30/04/2010 £7.98
336392BRPA 31/05/2010 £7.98
336392BRPA 30/06/2010 £7.98
336392BRPA 31/07/2010 £7.98
336392BRPA 31/08/2010 £0.78
336392BRPA 31/08/2010 £0.00
336392BRPA 31/08/2010 £8.76
336392BRPA 10/09/2010 £8.76
I need to add the cover choice from the policy table for each entry in the Accounts table. The problem is that I need to get it to add the cover choice based on the month end date to give something that looks like this:
Policy_Id MonthEndDate PremiumPaid strCoverChoice
336392BRPA 31/08/2009 £7.98 P
336392BRPA 31/08/2009 £7.98 P
336392BRPA 30/09/2009 £7.98 P
336392BRPA 31/10/2009 £7.98 P
336392BRPA 30/11/2009 £7.98 P
336392BRPA 31/12/2009 £7.98 P
336392BRPA 31/01/2010 £7.98 P
336392BRPA 28/02/2010 £7.98 P
336392BRPA 31/03/2010 £7.98 P
336392BRPA 30/04/2010 £7.98 P
336392BRPA 31/05/2010 £7.98 PX
336392BRPA 30/06/2010 £7.98 PX
336392BRPA 31/07/2010 £7.98 P5
336392BRPA 31/08/2010 £0.78 P5
336392BRPA 31/08/2010 £0.00 P5
336392BRPA 31/08/2010 £8.76 P5
336392BRPA 10/09/2010 £8.76 P5
The cover choice changed on the 27/05/2010 and 12/07/2010 so all entries in the accounts table with a month end dates after these dates will have the corresponding cover choice. This is the first time I've used a forum like this so apologies if I've not followed the correct posting convention bu any help would be appreciated as I'm stumped..
Comment