Home » SQL & PL/SQL » SQL & PL/SQL » Subtracting Years from As_Of_Date (PL/SQL, Version 9.0.6.1665)
Subtracting Years from As_Of_Date [message #632054] Fri, 23 January 2015 12:25 Go to next message
jburdell
Messages: 2
Registered: January 2015
Location: Boston
Junior Member
Hi, I am running a performance query where I want to get Yearly performance for multiple years with As_Of_date as a parameter of the query. I was wondering whether there is a way to subtract one year of the as_of_date so that you only need to input one date and it gets you performance for multiple years.

Equally if you know an easier way to do this then I would appreciate the help. I have included the query below.

select agh.grp_id,
agh.perf_incep_dt as "Since Incept Dt",

Performance package(agh.grp_id,'T','s','C','&as_of_date1',12,agh.base_curcy_cd) as "2014",
Performance package(agh.grp_id,'T','s','C','&as_of_date2',12,agh.base_curcy_cd) as "2013",
Performance package(agh.grp_id,'T','s','C','&as_of_date3',12,agh.base_curcy_cd) as "2012",
Performance package(agh.grp_id,'T','s','C','&as_of_date4',12,agh.base_curcy_cd) as "2011",
Performance package(agh.grp_id,'T','s','C','&as_of_date5',12,agh.base_curcy_cd) as "2010",
Performance package(agh.grp_id,'T','s','C','&as_of_date6',12,agh.base_curcy_cd) as "2009",
Performance package(agh.grp_id,'T','s','C','&as_of_date7',12,agh.base_curcy_cd) as "2008",
Performance package(agh.grp_id,'T','S','C','&as_of_date8',12,agh.base_curcy_cd) as "2007",
Performance package(agh.grp_id,'T','S','C','&as_of_date9',agh.perf_incep_dt,agh.base_curcy_cd) as "Since Incept"

from accountgrouptable agh
where agh.grp_id = '&grp_id'
Re: Subtracting Years from As_Of_Date [message #632057 is a reply to message #632054] Fri, 23 January 2015 12:26 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/
Re: Subtracting Years from As_Of_Date [message #632058 is a reply to message #632057] Fri, 23 January 2015 12:35 Go to previous messageGo to next message
jburdell
Messages: 2
Registered: January 2015
Location: Boston
Junior Member
Apologies for the format of the code. As I said above I am seeking a way to be able to remove the multiple As of Dates that I currently have in this query. I know it is possible to use subtract with sysdate but was wondering if there is anything similar I could use here.

Thank you

select agh.grp_id,
  agh.perf_incep_dt as "Since Incept Dt",
  
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date1',12,agh.base_curcy_cd) as "2014",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date2',12,agh.base_curcy_cd) as "2013",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date3',12,agh.base_curcy_cd) as "2012",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date4',12,agh.base_curcy_cd) as "2011",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date5',12,agh.base_curcy_cd) as "2010",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date6',12,agh.base_curcy_cd) as "2009",
  perfserv_pkg.RtP(agh.grp_id,'T','s','C','&as_of_date7',12,agh.base_curcy_cd) as "2008",
  perfserv_pkg.RtP(agh.grp_id,'T','S','C','&as_of_date8',12,agh.base_curcy_cd) as "2007",
  perfserv_pkg.RtP(agh.grp_id,'T','S','C','&as_of_date9',agh.perf_incep_dt,agh.base_curcy_cd) as "Since Incept"
  
from wmc.acct_group_hst_tbl agh
where agh.grp_id = '&grp_id'
 
Re: Subtracting Years from As_Of_Date [message #632061 is a reply to message #632058] Fri, 23 January 2015 13:03 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Realize we only know what you post here.

we don't have your tables, data, or requirements.

I be honest with you I have no idea what the correct answer would look like since I don't understand what you are asking about.
Re: Subtracting Years from As_Of_Date [message #632063 is a reply to message #632054] Fri, 23 January 2015 13:10 Go to previous messageGo to next message
joy_division
Messages: 4963
Registered: February 2005
Location: East Coast USA
Senior Member
Look at the function ADD_MONTHS.
Re: Subtracting Years from As_Of_Date [message #632068 is a reply to message #632063] Fri, 23 January 2015 14:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

With the link. Wink

Re: Subtracting Years from As_Of_Date [message #632069 is a reply to message #632068] Fri, 23 January 2015 16:10 Go to previous message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
select add_months(sysdate,-12) from dual;
Previous Topic: How to find first prior number from current date
Next Topic: need to get perfect query
Goto Forum:
  


Current Time: Fri Sep 04 13:10:45 CDT 2026