Latest Row [message #472995] |
Wed, 25 August 2010 04:45 |
yknev
Messages: 38 Registered: August 2010
|
Member |
|
|
Hi,
How to find the latest row(sigle row) using fa_distributin_history and fa_deprn_detail.
I want columns like below from above two tables
fdh.distribution_id fdh.locaton_id fd.ytd_deprn fd.deprn_amount
Thanks & Regards,
Yknev
|
|
|
Re: Latest Row [message #473007 is a reply to message #472995] |
Wed, 25 August 2010 06:32 |
|
Alien
Messages: 292 Registered: June 1999
|
Senior Member |
|
|
Hi,
it depends on your requirement for assets that have not been depreciated yet.
I think the following should get you started:
select fdh.distribution_id, fdh.location_id, fd.ytd_deprn, fd.deprn_amount
from (select row_number() over (partition by dist.book_type_code,dist.asset_id
order by dist.date_effective desc) rn
, dist.book_type_code
, dist.asset_id
, dist.distribution_id
, dist.location_id
from fa_distribution_history dist) fdh
, (select row_number() over (partition by dd.asset_id, dd.book_type_code
order by period_counter desc) rn
, ytd_deprn
, deprn_amount
, asset_id
, book_type_code
, distribution_id
from fa_deprn_detail dd) fd
where fd.distribution_id = fdh.distribution_id
and fd.book_type_code = fdh.book_type_code -- Not required, after the join on distribution_id
and fd.asset_id = fdh.asset_id -- But it allows the optimizer a better cardinality estimate.
and fdh.rn=1
and fd.rn=1;
Regards,
Arian
|
|
|
Re: Latest Row [message #473047 is a reply to message #473007] |
Wed, 25 August 2010 10:18 |
eric62
Messages: 24 Registered: January 2009
|
Junior Member |
|
|
Hi.
You can't join
fd.book_type_code = fdh.book_type_code
In fa_distribution_history, the book is always corporate book.
So if you want data for tax book, you won't find it.
|
|
|
|
|
|
Re: Latest Row [message #473865 is a reply to message #473390] |
Wed, 01 September 2010 04:39 |
yknev
Messages: 38 Registered: August 2010
|
Member |
|
|
Hi Alien,
Using above query. How to restrict the Remaining months is reaching to zero.i.e we don't want once the asset is expired(service of asset is completed).
Regards,
Yknev.
[Updated on: Wed, 01 September 2010 05:45] Report message to a moderator
|
|
|
Re: Latest Row [message #473885 is a reply to message #473865] |
Wed, 01 September 2010 07:30 |
eric62
Messages: 24 Registered: January 2009
|
Junior Member |
|
|
Hello
You have to use FA_BOOKS.
- with you asset_Id (FA_BOOOKS.ASSET_ID = Your asset_id)
- with your book ( FA_BOOOKS.BOOK_TYPE_CODE = Your book) if you select a book
- The effective Record (FA_BOOOKS.TRANSACTION_HEADER_ID_OUT IS NULL)
- Asset not completely expired (FA_BOOOKS.PERIOD_COUNTER_FULLY_RESERVED IS NULL )
- Asset not completely retired (FA_BOOOKS.PERIOD_COUNTER_FULLY_RETIRED IS NULL )
Regards
Eric.
|
|
|
|