I have a task that needs to return the last value and the previous to last value on the same row.
I know I can return two rows, but for mailmerging purposes, I need these values on the same row.
For example, to keep things simple, we have 2 tables:
Property Table
PrID (Primary Key), Address
1 , 21 High St
2, 41 Smith Road
Rent Table
PrID (Foreign Key), Date, Amount
1, 01/04/2007, 500
1, 01/10/2007, 450
1, 01/04/2008, 600
2, 04/11/2006, 575
2, 04/03/2007,600
I want the resuts to show
PrID, Address, Date, Amount, Previous Amount
1, 21 High St, 01/04/2008, 600,450
2, 41 Smith Road, 04/03/2007,600,575
The previous amount is based on the amount associated with the penultimate item by date, not by value.
Because of other field values in the tables not showing here, I can easily get at the penultimate value, what I am unable to do is to display this value on the same row.
Not sure if it can be achieved or not.
Thanks for any help.
**********************************
There is more than one way to skin a cat...but who wants a skinned cat?
I know I can return two rows, but for mailmerging purposes, I need these values on the same row.
For example, to keep things simple, we have 2 tables:
Property Table
PrID (Primary Key), Address
1 , 21 High St
2, 41 Smith Road
Rent Table
PrID (Foreign Key), Date, Amount
1, 01/04/2007, 500
1, 01/10/2007, 450
1, 01/04/2008, 600
2, 04/11/2006, 575
2, 04/03/2007,600
I want the resuts to show
PrID, Address, Date, Amount, Previous Amount
1, 21 High St, 01/04/2008, 600,450
2, 41 Smith Road, 04/03/2007,600,575
The previous amount is based on the amount associated with the penultimate item by date, not by value.
Because of other field values in the tables not showing here, I can easily get at the penultimate value, what I am unable to do is to display this value on the same row.
Not sure if it can be achieved or not.
Thanks for any help.
**********************************
There is more than one way to skin a cat...but who wants a skinned cat?