Wednesday, 16 April 2014

FAR Query and Base DB Loading and Unloading and Function Creation

--------------------------------------------------------------------
How to get table name and column name in base DB
------------------------------------------------------------------
 select * from systab where table_name='required Table Name'
SYSCOLUMNS
select tname from sys.SYSCOLUMNS where cname = 'columnname';
--------------------------------------------------------------
CREATE TABLE TEST_DBSchema.TEST_UTLZ(
   Name          varchar(50)    NULL IQ UNIQUE (255) ,
    OUR_TIME            datetime    NULL IQ UNIQUE (255) ,
    HW_Usage            numeric(18,0)  NULL IQ UNIQUE (255)
    )

 Environment
set temporary option escape_character = 'ON'
load table TEST_DBSchema.TEST_UTLZ(Name ',', OUR_TIME ',', HW_Usage '\X0A')from '/tmp/1.csv'
ESCAPES OFF QUOTES OFF
WITH CHECKPOINT ON;

--Trasfering file from to Target server.
scp /tmp/USER/1.csv user@190.167.75.12:/tmp
Change owner
chown dbview:oinstall 1.csv
chmod 777 1.csv
scp /tmp/Tahir/1.csv user@190.167.75.12:/tmp

Prompt Linux
source /opt/base/30/1.sh
dbisql -c "uid=DBA;pwd=dbapassword;eng=$ENG" -nogui Uti.sql
Linux:/tmp # vi Uti.sql
load table TEST_DBSchema.TEST_UTLZ(Name ',', OUR_TIME ',', HW_Usage '\X0A')from '/tmp/1.csv'
ESCAPES OFF QUOTES OFF
WITH CHECKPOINT ON;

Modifying CSV files using sed command
sed "1d" 1.csv > 2.csv
sed "1,2d" 1.csv > 2.csv
--------------------------------------------------------------------------------------------------------------------------
How to extract table from BASE DB to local disk
----------------------------------------------
Method
---------
hostname#:/dir1/dir2/dir3/dir4/dir5 # anyfile.sql
set temporary option temp_extract_name1 = '';
set temporary option temp_extract_append = off;
set temporary option Temp_Extract_Null_As_Empty = on;
set temporary option Temp_Extract_Column_Delimiter = '|';
set temporary option temp_extract_name1 = '/dirA/dirB/dirC/Table_Name_or_FileName.dat';
select * from tablename where age>=10 and age<50 and ROLNo='20';


HOW to create backup of a table in BASE DB
----------------------------------------------------------
select * into NEW_BACKUP_TABLE_1 from OLD_Table_WHOSE_BACKUP_YOUWANTTODO_1  


HOW TO GET TABLES NAME IN BASE DB
---------------------------------------------------------------
select 'select count(1) from '||case when creator=007 then 'PAK' when creator=006 then 'AJK' else 'ANYDBUSER' end||'.'||table_name||';'  
from   systable  where table_name like 'TABLENAME%'
and (upper(table_name) >='TABLENAMENO' and upper(table_name) <='TABLENAMENO') 
order by table_name; 

Get the table Names which Common Columns name such as Road_id  and road traffic.

Select table_name,column_name from  systabcol a

inner join systab  on  a.table_id=systab.table_id

where column_name ='col1' --such as  -- id number 

and exists (select 1 from systabcol b where a.table_id=b.table_id and b.column_name  ='col2')

HOW To Create Function in base  db
---------------------------------------------
create or replace  FUNCTION  FUN_NAME() returns int
begin
declare date_count int;
select datediff(dd,'18800202 08:00',getdate()) into date_count;
return date_count;
end
-----
create or replace  FUNCTION  Function_name(IN  give_time numeric(18))     
RETURNS numeric
BEGIN
     DECLARE con_time    numeric(18);
    set con_time =dateadd(ss,give_time+8*8600,'2017-1-1'); 
     return con_time;
end;

begin
declare date_count     int;
select datediff(dd,'20700101 08:00',getdate()) into date_count;
PRINT  date_count;   
end

 ---------storeprocedure
create or replace procedure PunjabUniversity.Own_Sp()
result("ID" numeric(3,0), "AT" varchar(20), "FIC" numeric(5,0))
on exception resume
begin
declare od char(10);
declare oq char(30000);
set od = cast(DATEDIFF( DAY, '1980/02/02', convert(char,getdate()-1,112)) as varchar(20)) ;
set oq='SELECT
ID,
AT,
SUM(A)/1024+ SUM(B)/1024  AS FIC FROM PunjabUnversity_TableNAME_'||od|| ' where ID=10,0000 group by ID,AT';
EXECUTE IMMEDIATE oq;
end

select * from PunjabUniversity.Own_Sp()

---------------------------------------------------------------------------------------------------------------------------ORACLEDBA-------------------------------

SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
  last_day(Dates) as Month,
  a.Category,
  a.kpi,
  round(avg(a.value),2) as Value 
  FROM TDB_CITY_WISE a
  WHERE DATES > '21-OCT-2018'
  AND CITY='K'
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  a.Category, a.kpi
 
alter session set "_ORACLE_SCRIPT"=true;
CREATE USER adhoc_user identified by orcl;
GRANT CONNECT TO adhoc_user;
GRANT DBA TO adhoc_user WITH ADMIN OPTION;

CREATE USER Tableau identified by orcl;
GRANT CONNECT TO Tableau;
GRANT DBA TO Tableau WITH ADMIN OPTION;


DROP USER SR;
CREATE USER SR identified by orcl;
GRANT CONNECT TO SR;
GRANT DBA TO SR WITH ADMIN OPTION;

SELECT * FROM "OT" where im_count=0

DELETE FROM "OT" where im_count=0

COMMIT 


---
CREATE USER username IDENTIFIED BY user1;


SELECT
  *
FROM
  DBA_SYS_PRIVS where GRANTEE= 'SYSASM' AND PRIVILEGE LIKE 'USER';
 
 
  DELETE FROM TDB WHERE PI <>'ATC'
  TRUNCATE TABLE TDB
  SELECT 
  FROM TDB where PI in ('PC','DC','CST');
 
        SELECT
        to_char(to_date(Dates), 'YYYYMM') as MM,
        SUM(val) as values
        FROM
        (
    SELECT to_char(to_date(Dates), 'YYYYMM'),
    SUM(CASE WHEN PI='CST' THEN  Value*10
             WHEN PI='DC' THEN  Value*45
             WHEN PI='PC' THEN  Value*45 END
    )/10,COUNT(DISTINCT Dates)
    as val
  FROM TDB where PI  in ('PC','DC','CST')
  GROUP BY to_char(to_date(Dates), 'YYYYMM')
  )as b
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM');
 
  to_char(to_date(Dates), 'MonthYYYY') as Month,
 
  SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
    last_day(Dates) as Month,
  to_number(to_char(to_date(Dates), 'w')) as Week,
  a.Category,
  a.PI,
  round(avg(a.value),2) as Value 
  FROM TDB a
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  to_number(to_char(to_date(Dates), 'w')),a.Category, a.PI
  ORDER BY 1 DESC;
 
  INSERT INTO TDB VALUES
  ('27-OCT-18','Data','S1',0.81)
  COMMIT
  DELETE FROM TDB WHERE Dates= '27-OCT-18' AND Value='0.80';
 
 
 
 
SELECT
        to_char(to_date(Dates), 'YYYYMM') as MM,
        SUM(val) as values
        FROM
        (
    SELECT Dates,to_char(to_date(Dates), 'YYYYMM'),PI,
    SUM(Value),COUNT(DISTINCT Dates)as val
  FROM TDB where category='FFM'
  and to_char(to_date(Dates), 'YYYYMM')='201810'
  GROUP BY Dates,to_char(to_date(Dates), 'YYYYMM'),PI;
  )as
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM');
 
  SELECT PI,count(dates) FROM TDB-- where category='FFM'
  GROUP BY PI
 
  DELETE FROM TDB where rowid < (SELECT MAX(rowid) FROM TDB WHERE Category=category)
 
  select * from MANUAL_TRANSACTION
 
  SELECT 
  to_char(to_date(Dates), 'YYYYMM'),
  sum(VALUE)/count(dates) FROM TDB
  where Dates between to_date('23-OCT-2018','dd-mon-yyyy') AND to_date('18-NOV-2018','dd-mon-yyyy')
    GROUP BY
  to_char(to_date(Dates), 'YYYYMM')
 
 
  SELECT
  Dates,
  to_char(to_date(Dates), 'YYYYMM') as MM,
    last_day(Dates) as Month,
  to_number(to_char(to_date(Dates), 'w')) as Week,
  a.Category,
  a.PI,
  round(avg(a.value),2) as Value 
  FROM TDB a
  GROUP BY
  Dates,
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  to_number(to_char(to_date(Dates), 'w')),a.Category, a.PI
 
 
 
 
 
    SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
    last_day(Dates) as Month,
  to_number(to_char(to_date(Dates), 'w')) as Week,
  a.Category,
  a.PI,
  round(avg(a.value),2) as Value 
  FROM TDB a
  GROUP BY
  Dates,
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  to_number(to_char(to_date(Dates), 'w')),a.Category, a.PI
 
 
 
     SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
  a.Category,PI,
  round(avg(a.value),2) as Value ,COUNT(DISTINCT DATES) , COUNT(DATES)
  FROM TDB a
  WHERE Category = 'Data'
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM'),a.Category,PI
 
  SELECT DATES, SUM(VALUE) FROM TDB
  WHERE DATES > '21-OCT-2018'
  GROUP BY DATES
  ORDER BY 1
 
  SELECT  Dates,avg(VALUE) FROM
     TDB
  WHERE PI = 'S1'
  GROUP BY DATES
  ORDER BY DATES
 
  INSERT INTO TDB VALUES('27-OCT-18','Data','S1',0.75)
 
  DELETE FROM TDB
  WHERE DATEs= to_Date('28-OCT-2018','dd-mon-yyyy') AND PI='S1' AND CATEGORY='Data' and value=0.8
 
  DELETE FROM TDB
  SELECT * FROM TDB WHERE DATEs=to_Date('15-NOV-2018','dd-mon-yyyy') AND PI='S1' AND CATEGORY='Data'
 
  SELECT dates,count(dates) FROM TDB group by dates having count(dates)>1
  COMMIT;
 
 
  SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
  SUM(
  CASE WHEN PI= 'ATC' THEN (value*10) ELSE 0 END
+CASE WHEN PI= 'PD' THEN (value*10)  ELSE 0 END
+CASE WHEN PI= 'S1' THEN (value*10) ELSE 0 END
  +CASE WHEN PI <>'Null' THEN (0.9*70) ELSE 0 END
)/10 as val
,
  round(avg(a.value),2) as Value
  FROM TDB a
  WHERE Category = 'Data'
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM')
 
TRUNCATE TABLE TDB
  DELETE FROM TDB a WHERE ROWID<(SELECT MAX(ROWID) FROM TDB b WHERE A.Dates = b.Dates)
  CREATE TABLE TDB2 AS SELECT DISTINCT * FROM TDB
 
  INSERT INTO TDB SELECT  *FROM  TDB2
  WHERE DATES BETWEEN to_Date('22-OCT-2018','dd-mon-yyyy') and to_Date('19-NOV-2018','dd-mon-yyyy')
 
  SELECT PI,MAX(dates), COUNT(1) from TDB GROUP BY PI
 
  TRUNCATE TABLE TDB_CITY_WISE
  CREATE TABLE TDB_CITY_WISE AS
  SELECT * FROM TDB WHERE 1=2
  DELETE FROM TDB_CITY_WISE where value >1
  PI <> 'ATC'
  COMMIT
 
  SELECT PI,dates,city,value   FROM
  TDB_CITY_WISE  where value >1
  PI = 'ATC';
 
  SELECT PI,MAX(dates),MIN(dates), COUNT(1) from TDB_CITY_WISE
  GROUP BY PI
 
  CREATE TABLE bsarwar.TDB2 AS
  SELECT * FROM TDB2;
 
  SELECT  dates,COUNT(1) FROM  TDB_CITY_WISE where city <> 'K' AND PI = 'ATC'
    GROUP BY dates
  ORDER BY DATES

 
  DELETE FROM TDB_CITY_WISE a WHERE a.rowid < (SELECT MAX(b.ROWID) FROM TDB_CITY_WISE b
  WHERE a.dates= b.dates AND a.city=b.city and a.PI=b.PI and a.category=b.category
  )
  COMMIT
 
  INSERT INTO TDB_CITY_WISE
  (DAtes,Category,PI,value,city)
  VALUES
  ('25-OCT-18',    'Data'     ,'S1',          0.77,      'K')
  rollback
 
  DELETE FROM TDB_CITY_WISE
  WHERE PI='DC';
 
  SELECT DISTINCT CITY FROM TDB_CITY_WISE
  where
  CITY NOT IN
  (
  'Any City'         
  )
 
  dates = '15-NOV-2018'
 
  SELECT /*+ PARALLEL(4) */
  count(1) FROM adhoc_user.data_user_traffic_nov2018;
 
  ANALYZE TABLE adhoc_user.data_user_traffic_nov2018 COMPUTE STATISTICS;
 
 
  SELECT * FROM adhoc_user.data_user_traffic_nov2018;
 
  WHERE to_char(traffic_mb) LIKE '%E%';
 
 
 
  SELECT
  Dates,
  to_char(to_date(Dates), 'YYYYMM') as MM,
  last_day(Dates) as Month,
  to_number(to_char(to_date(Dates), 'w')) as Week,
  a.City,
  a.Category,
  a.PI,
  round(avg(a.value),2) as Value 
  FROM TDB_CITY_WISE a
  WHERE DATES > '21-OCT-2018'
  GROUP BY
  Dates,
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  to_number(to_char(to_date(Dates), 'w')),
  a.City,
  a.Category, a.PI
 
 
 
 
 
 
 
 
 
  SELECT
  to_char(to_date(Dates), 'YYYYMM') as MM,
  last_day(Dates) as Month,
  a.Category,
  a.PI,
  round(avg(a.value),2) as Value 
  FROM TDB_CITY_WISE a
  WHERE DATES > '21-OCT-2018'
  AND CITY='K'
  GROUP BY
  to_char(to_date(Dates), 'YYYYMM'),
  last_day(Dates),
  a.Category, a.PI
 
alter session set "_ORACLE_SCRIPT"=true;
CREATE USER adhoc_user identified by orcl;
GRANT CONNECT TO adhoc_user;
GRANT DBA TO adhoc_user WITH ADMIN OPTION;

CREATE USER Tableau identified by orcl;
GRANT CONNECT TO Tableau;
GRANT DBA TO Tableau WITH ADMIN OPTION;


DROP USER SR;
CREATE USER SR identified by orcl;
GRANT CONNECT TO SR;
GRANT DBA TO SR WITH ADMIN OPTION;

SELECT * FROM "OT" where im_count=0

DELETE FROM "OT" where im_count=0

COMM


--------------------------------------------------------------------------------------------------------------------------------------------------------
Curson Definition in Oracle VS Python code independently written
-----------------------------------------------------------------------------------------------------------------------------------------------------------


DECLARE
CURSOR Data_curson IS select HOURR,count(1)   from  Your_Table_Name where HOURR between DATE '2013-05-21'  and DATE '2013-05-22'group by HOURR;
hour_name Your_Table_Name.HOURR%type;
h_count   integer;
BEGIN
OPEN Data_curson;
LOOP
FETCH Data_curson INTO hour_name,h_count ;
IF Data_curson%NOTFOUND
THEN
EXIT;
END IF;
Dbms_output.put_line('hour_name Fetched:'||hour_name);
Dbms_output.put_line('h_count Fetched:'||h_count);
END LOOP;
--Dbms_output.put_line('Total rows fetched is'||Data_curson%R0WCOUNT);
CLOSE Data_curson;
END;
--------------------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------
#how to open a CSV file and read each row, as well as reference specific data on each row.       
#-------------------------------------------------------------       
#csv file is give below
# 0       1 2 3    index no
#1/2/2014,5,8,red
#1/3/2014,5,2,green
#1/4/2014,9,1,blue   

import csv

with open('D:\Test.csv') as csvfile:
    readCSV = csv.reader(csvfile, delimiter=',')
    dates = []
    colors = []
    for row in readCSV:
        color = row[3]
        date = row[0]

        dates.append(date)
        colors.append(color)

    print(dates[1]) #will print 1/2/2014
    print(colors[1]) #will print red

--------------------------------------------------------------------------------------------------------------
Oracle Fixed Assets Query
 ---------------------------------------------------------------------------------------------------------------------------
select
'Freehold Land own' Particulars,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Land%')+nvl(getRetirements_FAR_THK(&FromDate,'%Land%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Land%')+nvl(getRetirements_FAR_THK(&FromDate,'%Land%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Land%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Land%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Land%')+nvl(getRetirements_FAR_THK(&FromDate,'%Land%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Land%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Land%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Land%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Land%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Land%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Land%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Leasehold Improvement',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Leasehold%')+nvl(getRetirements_FAR_THK(&FromDate,'%Leasehold%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Leasehold%')+nvl(getRetirements_FAR_THK(&FromDate,'%Leasehold%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Leasehold%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Leasehold%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Leasehold%')+nvl(getRetirements_FAR_THK(&FromDate,'%Leasehold%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Leasehold%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Leasehold%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code='OPR FA TAN FH.Leasehold Improvement.NA.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code='OPR FA TAN FH.Leasehold Improvement.NA.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code='OPR FA TAN FH.Leasehold Improvement.NA.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code='OPR FA TAN FH.Leasehold Improvement.NA.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Computers & Software',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%COMPUTER%')+nvl(getRetirements_FAR_THK(&FromDate,'%COMPUTER%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%COMPUTER%')+nvl(getRetirements_FAR_THK(&FromDate,'%COMPUTER%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%COMPUTER%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%COMPUTER%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%COMPUTER%')+nvl(getRetirements_FAR_THK(&FromDate,'%COMPUTER%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%COMPUTER%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%COMPUTER%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%COMPUTER%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%COMPUTER%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%COMPUTER%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%COMPUTER%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Vehicles',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%VEHICLES%')+nvl(getRetirements_FAR_THK(&FromDate,'%VEHICLES%'),0) OpenBal,
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%VEHICLES%')+nvl(getRetirements_FAR_THK(&FromDate,'%VEHICLES%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%VEHICLES%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%VEHICLES%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%VEHICLES%')+nvl(getRetirements_FAR_THK(&FromDate,'%VEHICLES%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%VEHICLES%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%VEHICLES%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%VEHICLES%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%VEHICLES%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%VEHICLES%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like '%VEHICLES%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Network Batteries',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Network Batteries%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Network Batteries%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Network Batteries%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Network Batteries%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Network Batteries%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Network Batteries%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Network Batteries%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Network Batteries%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Network Batteries%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Network Batteries%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like 'OPR FA TAN FH.INFRASTRUCTURE.Infra-Network Batteries.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like 'OPR FA TAN FH.INFRASTRUCTURE.Infra-Network Batteries.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like 'OPR FA TAN FH.INFRASTRUCTURE.Infra-Network Batteries.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like 'OPR FA TAN FH.INFRASTRUCTURE.Infra-Network Batteries.NA'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Telco Tools',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%')+nvl(getRetirements_FAR_THK(&FromDate,'%INFRASTRUCTURE.Infra-Telco%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%')+nvl(getRetirements_FAR_THK(&FromDate,'%INFRASTRUCTURE.Infra-Telco%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%')+nvl(getRetirements_FAR_THK(&FromDate,'%INFRASTRUCTURE.Infra-Telco%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%INFRASTRUCTURE.Infra-Telco%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%INFRASTRUCTURE.Infra-Telco%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%INFRASTRUCTURE.Infra-Telco%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%INFRASTRUCTURE.Infra-Telco%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%INFRASTRUCTURE.Infra-Telco%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%INFRASTRUCTURE.Infra-Telco%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Imported & Local Equipment Cost',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%Equipment%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%Equipment%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%Equipment%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%Equipment%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%Equipment%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%Equipment%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%Equipment%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%Equipment%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%Equipment%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%Equipment%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%Equipment%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%Equipment%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%Equipment%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%Equipment%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Services & Civil Works Cost',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%vi% Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%vi% Cost%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%vi% Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%vi% Cost%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%vi% Cost%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%vi% Cost%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-%vi% Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%vi% Cost%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Infra-%vi% Cost%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-%vi% Cost%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%vi% Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%vi% Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%vi% Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-%vi% Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Furniture',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%FURNITURE%')+nvl(getRetirements_FAR_THK(&FromDate,'%FURNITURE%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%FURNITURE%')+nvl(getRetirements_FAR_THK(&FromDate,'%FURNITURE%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%FURNITURE%'),0)  ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%FURNITURE%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%FURNITURE%')+nvl(getRetirements_FAR_THK(&FromDate,'%FURNITURE%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%FURNITURE%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%FURNITURE%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%FURNITURE%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%FURNITURE%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%FURNITURE%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%FURNITURE%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Office Equipment',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%')+nvl(getRetirements_FAR_THK(&FromDate,'%OFFICE EQUIPMENT%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%')+nvl(getRetirements_FAR_THK(&FromDate,'%OFFICE EQUIPMENT%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%')+nvl(getRetirements_FAR_THK(&FromDate,'%OFFICE EQUIPMENT%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%OFFICE EQUIPMENT%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%OFFICE EQUIPMENT%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%OFFICE EQUIPMENT%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%OFFICE EQUIPMENT%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
--varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%OFFICE EQUIPMENT%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%OFFICE EQUIPMENT%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Pre-operating Cost',OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Pre-operating Cost%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,nvl(R.Retirments,0)Retirements_Adjustments,OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Pre-operating Cost%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%'),0) ACC_DeprnAS_At_30_June,nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Pre-operating Cost%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Pre-operating Cost%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Pre-operating Cost%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Pre-operating Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Pre-operating Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
--varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Pre-operating Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Pre-operating Cost%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
union
select
'Infra-Financial Charges',
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Financial Charges%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Financial Charges%'),0) OpenBal,      --nvl(R.Retirments,0)
nvl(A.Additions,0) Addition,
nvl(R.Retirments,0)Retirements_Adjustments,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Financial Charges%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Financial Charges%'),0)+nvl(A.Additions,0)-nvl(R.Retirments,0) ClosingBal,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Financial Charges%'),0) ACC_DeprnAS_At_30_June,
nvl(C.DeprnAsNOV13,0)Deprn_As_NOV13,
nvl(RD.Retirments_Deprn,0) Retirements_Adjustments,
nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Financial Charges%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)   Accumu_DepreAT_30_11_13,
OpenBal_FAR_THK(add_months(&FromDate,0)-1,'%Infra-Financial Charges%')+nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Financial Charges%'),0)+nvl(A.Additions,0)-nvl(getRetirements_FAR_THK(&FromDate,'%Infra-Financial Charges%'),0) -nvl(R.Retirments,0)-(nvl(OpenBal_Deprn_FAR_THK_AT30JUN( add_months(&FromDate,0)-1,'%Infra-Financial Charges%'),0)+nvl(C.DeprnAsNOV13,0)-nvl(RD.Retirments_Deprn,0)) WDV_as_at_30_11_13
from
(select
sum(ab.cost) Additions
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Financial Charges%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and(select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service between &FromDate and &ToDate)A,
(select
sum(re.cost_retired) Retirments
from
fa_retirements re
where
re.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Financial Charges%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'6-DEC-13'--end subqurey inner
and re.date_retired  between &FromDate and &ToDate)R, --variablle '30-NOV-13'
 --varibale year wise 'JUN-13',JUN-12, JUN-11
(select sum(ds.ytd_deprn)DeprnAsNOV13
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Financial Charges%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))----'6-DEC-13'--end subqurey inner
and dp.period_name=to_char(add_months(&Todate,12),'MON-YY'))C,--and dp.period_name='NOV-14'
(select
        sum(a.adjustment_amount) Retirments_Deprn
from
fa_adjustments a
where
a.asset_id in (select ab.asset_id from fa_books ab,fa_additions_b ad,fa_additions_tl adt,fa_transaction_headers th where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code  like '%Infra-Financial Charges%'
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null))--'06-DEC-13' end subqurey inner
and a.source_type_code = 'RETIREMENT'
and a.adjustment_type = 'RESERVE'
and a.period_counter_adjusted between (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&FromDate,12),'MON-YY'))) and (select  p.period_counter from fa_deprn_periods p where p.period_name in (to_char(add_months(&ToDate,12),'MON-YY')) ))RD
------------------------------------------------------------------------------------------------------------------------------------------
create or replace function OpenBal_FAR_THK(enddate date, catagory varchar2 ) return number is
  ResultOpenbal number;
begin
  select
sum(ab.cost)  into ResultOpenbal
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like  catagory            
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null)--'6-DEC-13'
and ab.date_placed_in_service<=enddate;
  return(ResultOpenbal);
end OpenBal_FAR_THK;
-----------------------------------------------------------------------------------------------------------------------------------------------------------
create or replace function OpenBal_Deprn_FAR_THK_AT30JUN(enddate date, catagory varchar2) return number is
  OpenBalAt30JunResult number;
begin
select sum(DEP.Acc_Depreciation_at_30JUN_13)  into OpenBalAt30JunResult from(
select
CASE  WHEN ab.period_counter_life_complete is not null   then
(select sum(dd.deprn_reserve) from fa_deprn_detail dd where dd.asset_id=th.asset_id
 and dd.deprn_run_date in(select max(ds.deprn_run_date)
 from fa_deprn_summary ds where ds.asset_id=th.asset_id))
WHEN ab.period_counter_life_complete is  null then
(select sum(ds.deprn_reserve)
from
fa_deprn_summary ds,
fa_deprn_periods dp
where
ds.period_counter=dp.period_counter
and ds.asset_id=th.asset_id
and dp.period_name=to_char(add_months(enddate,0)-1,'MON-YY'))--JUN-13 PeriodName variable'to_char(add_months(&enddate,0)-1,'MON-YY')' will be passed from function to get the PeriodName, from FROMDate Parameter.
END Acc_Depreciation_at_30JUN_13
from
fa_books ab,
fa_additions_b ad,
fa_additions_tl adt,
fa_transaction_headers th
where
ab.asset_id=ad.asset_id
and th.asset_id=adt.asset_id
and th.asset_id=ad.asset_id
and ad.attribute_category_code like catagory
and th.transaction_type_code='ADDITION'
and ab.date_ineffective is null-- to get the present row
and ab.transaction_header_id_out is null-- to get assets which are not retirement yet
and th.date_effective between '15-SEP-05'and (select  to_char(max(dp.period_close_date),'DD-MON-YY') from fa_deprn_periods dp where
dp.period_close_date is not null) --NOV-14 --'5-AUG-13'--30-_june_06 that 1-JUL-06  to  30-JUN-13
and ab.date_placed_in_service<=enddate
)DEP;
--dbms_output.put_line(x);
return(OpenBalAt30JunResult);
end OpenBal_Deprn_FAR_THK_AT30JUN;

© 2014 Microsoft Terms Privacy & cookies Developers English (United States)
tahir khalid
Facebook
Facebook
Connect
Twitter
Twitter
Sign up
Already on Twitter?
Content from FacebookTwitter
Learn more|Turn off
     

Saturday, 25 January 2014

GSM_NETWORK_PICTURE


FA_Ad_Query_Example

select
adb.asset_number,
adb.tag_number,
adt.description,
bks.date_placed_in_service,
adb.attribute3 ,
adb.attribute4 ,
adb.serial_number,
adb.current_units,
bks.prorate_convention_code,
bks.deprn_method_code,
bks.life_in_months,
bks.original_cost,
to_number(substr(get_asset_depren(bks.asset_id),1,instr(get_asset_depren(bks.asset_id),'-')-1 )) YEAR_To_DATE_DEPRN,
to_number(substr(get_asset_depren(bks.asset_id),instr(get_asset_depren(bks.asset_id),'-')+1 ))   Acc_DEPRN,
bks.original_cost-substr(wtc_get_asset_depren(bks.asset_id),instr(get_asset_depren(bks.asset_id),'-')+1 )NBV  
from 
fa_books bks,
fa_additions_b adb,
fa_additions_tl adt,
fa_categories_b cata,
fa_transaction_headers ts
where 
bks.transaction_header_id_out is null
and bks.date_ineffective  is null
and bks.book_type_code='YourASSETS BOOK'
and bks.asset_id=ts.asset_id
and adb.asset_id=ts.asset_id
and adt.asset_id=bks.asset_id
and adb.asset_category_id=cata.category_id
and ts.transaction_type_code='ADDITION'
and ts.date_effective between (select
to_char(p.period_open_date,'DD-MON-YY')
from 
fa_deprn_periods p 
where

p.calendar_period_open_date>=&fromDate
and p.calendar_period_close_date<=&toDate) and   (select
to_char(p.period_close_date,'DD-MON-YY')
from 
fa_deprn_periods p 
where
p.calendar_period_open_date>=&fromDate
and p.calendar_period_close_date<=&toDate); --  period open date and period close date --period name=NOV-14,OCT-14,SEP-14



-----------------------------------------------
select bks.asset_id,bks.date_effective
from 
fa_books bks
where bks.date_effective between '22-NOV-13' and '10-DEC-13' --  period open date and period close date --period name
---------------------------------------------------------------------------------------------------------------------------------
select
to_char(p.period_open_date,'DD-MON-YY')
from 
fa_deprn_periods p 
where
p.calendar_period_open_date>=&fromDate
and p.calendar_period_close_date<=&toDate;
----------------------------------------------------------------------------------------------------------------------------------
select
to_char(p.period_close_date,'DD-MON-YY')
from 
fa_deprn_periods p 
where
p.calendar_period_open_date>=&fromDate
and p.calendar_period_close_date<=&toDate;
-----------------------------------------------
--Note

create or replace function Get_Asset_Depren(xxAssetId in number) return varchar2
is
    l_deprn_reserve             NUMBER;
    l_ytd_deprn                 NUMBER; -- Year-to-Date Depreciation
    l_bonus_deprn_reserve       NUMBER;
    l_bonus_ytd_deprn           NUMBER;
    l_reval_reserve             NUMBER;
    l_real_cost                 NUMBER;
    dummy_num                   NUMBER;
    dummy_char                  VARCHAR2 (100);
    dummy_bool                  BOOLEAN;
    l_run_mode                  VARCHAR2 (20)  := 'STANDARD';
    V_SOB_ID                    NUMBER:=0000;
    V_log_level_rec             APPS.FA_API_TYPES.log_level_rec_type;
   
 begin
    apps.fa_query_balances_pkg.query_balances(x_asset_id                  => xxAssetId,
                                              x_book                      => 'YOUR ASSETS BOOK',
                                              x_period_ctr                =>0,
                                              x_dist_id                   =>0,
                                              x_run_mode                  => l_run_mode,
                                              x_cost                      => l_real_cost,
                                              x_deprn_rsv                 => l_deprn_reserve,
                                              x_reval_rsv                 => l_reval_reserve,
                                              x_ytd_deprn                 => l_ytd_deprn,
                                              x_ytd_reval_exp             => dummy_num,
                                              x_reval_deprn_exp           => dummy_num,
                                              x_deprn_exp                 => dummy_num,
                                              x_reval_amo                 => dummy_num,
                                              x_prod                      => dummy_num,
                                              x_ytd_prod                  => dummy_num,
                                              x_ltd_prod                  => dummy_num,
                                              x_adj_cost                  => dummy_num,
                                              x_reval_amo_basis           => dummy_num,
                                              x_bonus_rate                => dummy_num,
                                              x_deprn_source_code         => dummy_char,
                                              x_adjusted_flag             => dummy_bool,
                                              x_transaction_header_id     => -1,
                                              x_bonus_deprn_rsv           => l_bonus_deprn_reserve,
                                              x_bonus_ytd_deprn           => l_bonus_ytd_deprn,
                                              x_bonus_deprn_amount        => dummy_num,
                                              X_IMPAIRMENT_RSV            => dummy_num,
                                              X_YTD_IMPAIRMENT            => dummy_num,
                                              X_IMPAIRMENT_AMOUNT         => dummy_num,
                                              X_CAPITAL_ADJUSTMENT        => dummy_num,
                                              X_GENERAL_FUND              => dummy_num,
                                              X_MRC_SOB_TYPE_CODE         => NULL,
                                              X_SET_OF_BOOKS_ID           => V_SOB_ID,
                                              p_log_level_rec             => V_log_level_rec
                                              );

 --dbms_output.put_line(l_ytd_deprn||'   '||l_deprn_reserve);
 return  l_ytd_deprn||'-'||l_deprn_reserve;
 END;
--Summary for the above.
/*First get the asset id from the fa_transaction_headers table where transaction_type_code='ADDITION' and also 
where the date_effective of the fa_transaction_headers is between the period_open_date and period_close_date taken from
the fa_deprn_period table i.e; when the fa_derpn period is opened and closed and shown above */

Tuesday, 21 January 2014

SQL JOINS Exmaples

Example Tables

Employee table

LastName        DepartmentID (FroeignKey)
Rafferty 31
Jones            33
Heisenberg 33
Robinson 34
Smith            34
John            NULL


Department table

DepartmentID DepartmentName
31                        Sales
33                        Engineering
34                        Clerical
35                       Marketing



SELECT *
FROM employee JOIN department
  ON employee.DepartmentID = department.DepartmentID;


We can write equi-join as below,

SELECT *
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID;



Inner Join Result           ensures No Null values be matched

LastName   empid/depttid DepartmentName
Rafferty   31     Sales
Jones      33     Engineering
Heisenberg 33     Enginnering
Robinson   34     Clerical
Smith      34     Clerical




SELECT *
FROM employee LEFT OUTER JOIN department
  ON employee.DepartmentID = department.DepartmentID;

Alternative syntax


SELECT *
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID(+)

Outer Join Result            may contain Null values


LastName   empid/deptid     DepartmentName 
Rafferty             31   Sales
Jones                  33   Engineering
Heisenberg      33   Enginnering
Robinson          34    Clerical
Smith                  34    Clerical
John              NULL   NULL

Note outer Join  A left outer join returns all the values from an inner join plus all values in the left 

table that do not match to the right table.





Right outer Join 

SELECT *
FROM employee RIGHT OUTER JOIN department
  ON employee.DepartmentID = department.DepartmentID;


LastName   empid/deptid    DepartmentName 
Rafferty             31   Sales
Jones                 33   Engineering
Heisenberg     33   Enginnering
Robinson         34    Clerical
Smith                34    Clerical
NULL           NULL Marketing


Note
A right outer join returns all the values from the right table and matched values from the left table 
If no matching row from the "left" table (A) exists, NULL will appear in columns from A for those records 

that have no match in B.


Now Full outer Join combines both Left and right outer join results

SELECT *
FROM employee FULL OUTER JOIN department
  ON employee.DepartmentID = department.DepartmentID;



LastName   empid/deptid     DepartmentName 
Rafferty           31   Sales
Jones                33   Engineering
Heisenberg    33   Enginnering
Robinson        34            Clerical
Smith               34            Clerical
NULL           NULL Marketing
John           NULL   NULL