Solved

need a specific record from the query

Posted on 2012-03-27
2
317 Views
Last Modified: 2012-03-28
SELECT  
      fbv.book_type_code,
      fdp.period_name,  
      fab.asset_number,
       fab.description,
       fcb.segment1 || '.' || fcb.segment2 asset_category,
       fbv.original_cost original_asset_cost,
       DECODE (fbv.cost, 0, 0, (fbv.cost - fds.deprn_reserve)) net_book_value,
       fds.ytd_deprn,
       fds.deprn_reserve acc_deprn,
       fbv.date_placed_in_service,
       fbv.deprn_method_code,
       (fbv.life_in_months / 12) life_in_years, fds.*
  FROM apps.fa_additions_v fab,
  apps.fa_categories_b fcb,
  apps.fa_books_v fbv,
       fa_deprn_summary fds,
      apps.fa_deprn_periods fdp--,
       --apps.fa_distribution_history fdh,
       --apps.gl_code_combinations gcc,
       --apps.fa_locations fl
WHERE     1 = 1
       AND fab.asset_id = fbv.asset_id
       AND fcb.category_id = fab.asset_category_id
       AND fbv.transaction_header_id_out IS NULL
       AND fdp.book_type_code = fbv.book_type_code
              AND fds.book_type_code = fbv.book_type_code
       and fdp.period_counter=fds.period_counter
       --AND fdh.asset_id = fbv.asset_id
       --AND fdh.code_combination_id = gcc.code_combination_id
       --AND fdh.location_id = fl.location_id
       AND fbv.transaction_header_id_out IS NULL
      -- AND fdh.transaction_header_id_out IS NULL
       AND fds.asset_id = fbv.asset_id
      AND  fbv.book_type_code  in  ('TPC US COMP TAX')-- ( 'TPC_US_COMP')--, 'TPC US COMP TAX')
    and asset_number = '39341'
     and fdp.period_name in ( 'Jan-2011', 'Feb-2011', 'Mar-2011', 'Apr-2011', 'May-2011',
      'Jun-2011', 'Jul-2011', 'Aug-2011', 'Sep-2011', 'Oct-2011', 'Nov-2011', 'Dec-2011')
asset-list.txt
0
Comment
Question by:pardeshirahul
2 Comments
 

Author Comment

by:pardeshirahul
ID: 37773692
the output i need only the max of period name records in this case DEC-11 is the max period for other assets it can be different month
0
 
LVL 20

Accepted Solution

by:
gatorvip earned 500 total points
ID: 37773824
Do you need "only the max of period name records" (i.e., the last period)? Or all the records associated with that period?

If the former, then you could do this:

select max( to_date(period_name, 'Mon-YYYY') )
from
...


If the latter, then add a rank() clause to your select:

select *
from
(
select ...
 , rank() over(order by to_date(fdp.period_name, 'MON-YYYY') desc) most_recent
from
...
)
where most_recent=1

Open in new window


Since rank() gives the same value to rows with the same ranking criteria, everything that corresponds to the most recent value in fdp.period_name will have a rank value of 1.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now