Current quarter and four future quarters

Hello Forum Members,
I have a config table with the following data:
Quarter Config Rep_date
Q1-2006|1|1/1/2006
Q2-2006|32|4/12/2006
Q3-2006|321|7/15/2006
Q4-2006|897|12/14/2006
Q1-2007|10|2/12/2007
Q2-2007|10|5/12/2007
Q4-2007|50|11/12/2007
Q1-2008|30|1/1/2008
Q2-2008|57|4/10/2008
Q4-2008|45|12/12/2008
Q3-2008|34|8/8/2008
Q4-2005|21|12/1/2005
Q3-2005|20|8/22/2005
Q2-2005|65|4/14/2005
Q1-2005|65|1/14/2005
Q3-2007|435|9/9/2007
I have to show current quarter and four future quarters in oracle form.
ie
Q4-2007|50|
Q1-2008|30|
Q2-2008|57|
Q3-2008|34|
Q4-2008|45|
Please advise me.
Thanks

Coming at it from a different angle, you could fix the data before doing the query. This makes the query much simpler, which is good if it has to be used in many places in the application. Obviously the best way would be to make the quarter column a date column, but that's not always possible. A view or a function-based index can do the same job:
DROP TABLE quarters;
CREATE TABLE quarters AS
SELECT a quarter, b config, To_Date(c,'MM/DD/YYYY') rep_date FROM(
  SELECT 'Q1-2006' a, 1 b, '1/1/2006' c FROM dual UNION ALL
  SELECT 'Q2-2006', 32, '4/12/2006' FROM dual UNION ALL
  SELECT 'Q3-2006', 321, '7/15/2006' FROM dual UNION ALL
  SELECT 'Q4-2006', 897, '12/14/2006' FROM dual UNION ALL
  SELECT 'Q1-2007', 10, '2/12/2007' FROM dual UNION ALL
  SELECT 'Q2-2007', 10, '5/12/2007' FROM dual UNION ALL
  SELECT 'Q4-2007', 50, '11/12/2007' FROM dual UNION ALL
  SELECT 'Q1-2008', 30, '1/1/2008' FROM dual UNION ALL
  SELECT 'Q2-2008', 57, '4/10/2008' FROM dual UNION ALL
  SELECT 'Q4-2008', 45, '12/12/2008' FROM dual UNION ALL
  SELECT 'Q3-2008', 34, '8/8/2008' FROM dual UNION ALL
  SELECT 'Q4-2005', 21, '12/1/2005' FROM dual UNION ALL
  SELECT 'Q3-2005', 20, '8/22/2005' FROM dual UNION ALL
  SELECT 'Q2-2005', 65, '4/14/2005' FROM dual UNION ALL
  SELECT 'Q1-2005', 65, '1/14/2005' FROM dual UNION ALL
  SELECT 'Q3-2007', 435, '9/9/2007' FROM dual
CREATE OR REPLACE FUNCTION get_qtr_date(p IN VARCHAR2) RETURN DATE DETERMINISTIC AS
BEGIN
  RETURN Add_Months(Trunc(To_Date(SubStr(p,4),'YYYY'),'YYYY'), (To_Number(SubStr(p,2,1))-1)*3);
END;
CREATE INDEX function_based ON quarters(get_qtr_date(quarter));
SELECT * FROM quarters
WHERE get_qtr_date(quarter) BETWEEN Trunc(SYSDATE-100,'Q') AND Add_Months(Trunc(SYSDATE-100,'Q'), 12)
ORDER BY get_qtr_date(quarter);
QUARTER CONFIG REP_DATE
Q3-2007    435 09-SEP-07
Q4-2007     50 12-NOV-07
Q1-2008     30 01-JAN-08
Q2-2008     57 10-APR-08
Q3-2008     34 08-AUG-08Another benefit of a function-based index on a column which has to take a specific format is that you can validate the data on the way in rather than checking it on the way out. For example:
CREATE OR REPLACE FUNCTION get_qtr_date(p IN VARCHAR2) RETURN DATE DETERMINISTIC AS
BEGIN
  IF InStr(p,'Q') != 1 THEN
    Raise_Application_Error(-20000, 'Invalid quarter format');
  END IF;
  RETURN Add_Months(Trunc(To_Date(SubStr(p,4),'YYYY'),'YYYY'), (To_Number(SubStr(p,2,1))-1)*3);
END;
INSERT INTO quarters VALUES('P3-2009',100,To_Date('10/10/2009','DD/MM/YYYY'));
ORA-20000: Invalid quarter format
ORA-06512: at "TEST.GET_QTR_DATE", line 4

Similar Messages

  • Balance sheet required for current quarter and previous quarter

    Hi Guys,
                 I am using 0FIGL_C10 cube for balance sheet report,i need to create balances for current quarter and previous quarter.
    user will enter the fisper, based on fisper it has to show the current quarter and previous quarter balance.
    how to calculate the quarter using fisper.

    you can use offset with ranges.
    or
    just offset of -1 , -2 & -3 seperately in 3 selections and add it in one column in formula (this will give u current quarter).
    similarly offset of -4, -5 , -6 will give u previous quarter result.
    total of 6 selection and 2 formulas. hide all selections from display.

  • How to get Current Quarter and Fiscal Quarter for a Date - Fiscal Year starts from 1st April

    Hi, 
    I need to calculate current quarter and fiscal quarter in my Sql query.
    I have a column for DateTime Datatype. 
    I need to find out Current Quarter Name like Q12012, Q22012, Q32012, Q42012 and Fiscal Quarter Name as well.
    Now Fiacal Year starts from 1st April, and Current Quarter starts from 1st Jan.
    For Current Quarter of 2012
    Jan-Mar = Q12012
    Apr-Jun = Q22012
    Jul-Sep = Q32012
    Oct-Dec = Q42012
    For Fiscal Quarter of 2012 ( starts from 1st Apr, 2011 )
    Apr2011-Jun2011 = Q12012
    Jul2011-Sep2011 = Q22012
    Oct2011-Dec2011 = Q32012
    Jan2011-Mar2012 = Q42012
    means if its 1st April, 2012,
    its a new Fiacal Year 2013 so Fiacal Quarter Name should be Q12013
    and its Current Quarter Name should be Q22012
    Can you help me to calculate this in a select query for given dates?
    Thanks in advance, 
    Nirav

    This should do it..
    Select
    FORMAT(datepart(quarter,getdate()),'Q#')+FORMAT(getdate(),'yyyy')

  • Get the Current Quarter  and Current Week from date

    Hi,
    I want to get the Current quarter and Current week from a given date, which function modules should i use?
    I tried using function module - 'HR_99S_GET_QUARTER' for getting the quarter but it is throwing an error while loading data. Moreover it doesnt exist in BI7.
    Similarly for current week.
    Please help. Sample code snippets would be appreciated.
    Thanks
    Jaya

    You can use FORM time_conversion wich is the one used by standard in Update Rules:
    You can select whether convert 0CALDAY to 0CALWEEK or whatever infobject formats you prefer...
      perform time_conversion
                using  '0CALDAY'
                       '0CALMONTH'
                        p_input_date
                        l_fscvtval
                changing RESULT
                         c_t_idocstate
                         c_subrc
                         c_abort.
      if c_subrc <> 0 or c_abort <> 0.
        exit.
      endif.
    form time_conversion
                   using i_timnm_from type rsiobjnm
                         i_timnm_to   type rsiobjnm
                         i_timvl
                         i_fiscvarnt  type t009b-periv
                   changing e_timvl
                            c_t_idocstate  type rsarr_t_idocstate
                            c_subrc   like sy-subrc
                            c_abort   like sy-subrc. "#EC *
    data: l_timvl  type rsd_chavl,
          l_result type rsd_chavl.
      IF i_timvl CO ' 0'.
        CLEAR e_timvl.
        EXIT.
      ENDIF.
      l_timvl = i_timvl.
      CALL FUNCTION 'RST_TOBJ_TO_DERIVED_TOBJ'
        EXPORTING
          i_timnm_from             = i_timnm_from
          i_timnm_to               = i_timnm_to
          i_timvl                  = l_timvl
          I_FISCVARNT              = i_fiscvarnt
          I_BUFFER                 = rs_c_true
        IMPORTING
          E_TIMVL                  = l_result
        EXCEPTIONS
          INCOMPATIBLE_TOBJS       = 1
          NO_INPUT_VALUE           = 2
          FISCVARNT_MISSING        = 3
          INPUT_NOT_NUMERIC        = 4
          WRONG_DATE               = 5
          WRONG_FISCPER            = 6
          X_MESSAGE                = 7
          OTHERS                   = 8
      e_timvl = l_result.
    ENDFORM.                  "TIME_CONVERSION

  • Display Current Quarter and Previous Quarter???

    Hi Gurus,
    I Had a requirement to display only the current Quarter and previous quarter in the report level using single quarter column.
    and my quarter value type is Q1 2013.
    Please anyone help me out on this asap/
    Thanks.

    Hi,
    Using time serious function you can acheive this requirement.
    http://obieetutorialguide.blogspot.in/2012/02/modeling-time-series-function-in-obiee.html
    OBIEE 11g Time Series Function
    or,
    Using presentation variable you can achieve this.
    Re: OBIEE 10g LY YTD returns YTD for past years
    The above thread for year you can change to qtr.
    Hope this help's
    Thanks,
    Satya

  • Current quarter and future quarters

    Hello Forum members:
    Can you please advice me on this:
    QUARTER SUM(CONFIG) Report_date
    Q1-2007 10 12-Jan-2007
    Q2-2007 10 21-Apr-2007
    Q3-2007 870 14-Aug-2007
    Q4-2007 50 14-Nov-2007
    Q4-2006 897 15-Dec-2007
    I want the following out put:
    Please note that the future quarters should have current quarter sum(config)
    Q4-2006 897
    Q1-2007 10
    Q2-2007 10
    Q3-2007 870
    Q4-2007 50
    Q1-2008 50
    Q2-2008 50
    Q3-2008 50
    Q4-2008 50
    My query returns the following:
    Q4-2006 897
    Q1-2007 10
    Q2-2007 10
    Q3-2007 870
    Q4-2007 50
    select quarter, sum(config)
    from quarter_test
    where rep_Date >= ADD_MONTHS(TRUNC(SYSDATE,'q'),-12) AND
    rep_date < ADD_MONTHS(TRUNC(SYSDATE,'q'),15)
    group by quarter
    order by substr(quarter,-4), substr(quarter,2,1);

    create table test5(quarter varchar2(7), config number, report_date date)
    select * from test5
    QUARTER     CONFIG     REPORT_DATE
    Q1-2007     10     1/12/2007
    Q2-2007     10     4/21/2007
    Q3-2007     870     8/14/2007
    Q4-2007     50     11/14/2007
    Q4-2006     897     12/15/2007
    select quarter, config from
    (select quarter, sum(config) config
    from test5
    where report_Date >= ADD_MONTHS(TRUNC(SYSDATE,'q'),-12) AND
    report_date < ADD_MONTHS(TRUNC(SYSDATE,'q'),15)
    group by quarter
    order by substr(quarter,4,4), substr(quarter,1,2))
    union all
    select 'Q'|| rownum || '-' || quarter, config from
    select substr(quarter,4,4)+1 quarter, config from
    select quarter, sum(config) config
    from test5
    where report_Date >= ADD_MONTHS(TRUNC(SYSDATE,'q'),-12) AND
    report_date < ADD_MONTHS(TRUNC(SYSDATE,'q'),15)
    group by quarter
    order by substr(quarter,4,4) desc, substr(quarter,1,2) desc
    where rownum=1)
    test, all_objects where rownum <=4
    QUARTER     CONFIG
    Q4-2006     897
    Q1-2007     10
    Q2-2007     10
    Q3-2007     870
    Q4-2007     50
    Q1-2008     50
    Q2-2008     50
    Q3-2008     50
    Q4-2008     50

  • Fetch current Quarter and pass it to custom query

    Hi
    I need to pass the current date and find the quarter in which the date falls.
    The start and end date of the quarter need to be passed as a query parameter, in a custom query in UI designer.
    My query is as follows
    As shown in above screenshot,I have close_dt_upd(datatype Date).This field should have end date of the quarter as a condition.
    Similarly I will have a field start_date which should have Start date of the quarter as condition.
    I got the following table in 1402 documentation.
    But the above transformation rule is not visible in  the query.
    Can anyone tell which namespace to use?
    How can I retrieve the current quarter start and end dates, and then pass them  to the above query?
    Thanks,
    Vijaya Chavan

    Hi,
    the most easiest and straight forward approach is
    - Ckick the "Binding" tab at the bottom of the Visual Editor
    - In the Bindings section click teh green plus icon and choose Generic Bindings | Attribute Value
    - point the iterator selection to the iterator used by the table
    - choose the column's attribute name from the list of attributes
    - Create a method on the ApplicatioNModule IMPL class (should take single argument)
    - expose it as a client interfaces so it shows in the Data Controls panel
    - In the "Binding" tab, create a method binding for this exposed method
    - point the method binding argument to #{bindings.column-attribute-name.inptValue}
    So whenever you need to pass the value on to the AM, you just call the method binding
    OperationBinding oper = (OperationBinding) bindings.get("name of method");
    oper.execute();
    Frank

  • How to get Current week and No of Weeks for each quarter!!

    Hi,
    As a part of report development I have to derive Current week and No.of Weeks in Curreny Query. Based on these information I have to calculate Phased target (Calculated KYF).
    Phased target = (Target for Quarter / No of weeks in Current Quarter) X Current Week.
    We have to derive Current Quarter and Current week from  Customer Exit (From Invoice date, which is an entry by Users at report level).
    My questions are:
    1) We have to derive Two Restricted key figures (by Calweek)  for derving No of weeks for Currnet Quarter and Current week in Query level. Based on this info, we have to derive Calculated kef figure for Phased target.
    2) And the output is 6 (ex:- 132008) char length for Current week and we have to pick Week info only and we have to populate RKF created for Current week. How we can achieve this.
    3) Regarding the No of weeks per for current quarter, we are writing Customer exit to determine Quarter and no of weeks, but how to bring this info in query level.
    4) Is there any standard code available (SAP Exit) to find Current week and No of Weeks in Current quarter.
    Regards,
    Suresh Molli

    Hi Venkat Molli,
    Follow the below step for the doing the same:
    1. Create a customer exit variable on calweek.
    2. Restrict the created variable for respective info object.
    3. To Populate the data write code in CMOD.
         in enhancement function module: EXIT_SAPLRRS0_001 -> in Include ZXRSRU01 write the below code:
    WHEN '<variable name>'.
         IF i_step = 1.
          CLEAR l_s_range.
          CALL FUNCTION 'RSVAREXIT_0P_CWEEK'
            IMPORTING
              e_t_range = lt_week.
          READ TABLE lt_week INTO l_s_range1 INDEX 1.
          v_last_week = l_s_range1-low+4(2).
          v_last_week =  v_last_week - 1.
          l_s_range1-low+4(2) = v_last_week.
          l_s_range-low      =  l_s_range1-low.
          l_s_range-sign     = 'I'.
          l_s_range-opt      = 'EQ'.
          APPEND l_s_range TO e_t_range.
        ENDIF.
    4. Execute the report.
    I hope you can handle you issue now.
    Assign points if it is helpful.
    Regards,
    S P.

  • How to derive  Current week and Number of Weeks for present quarter.

    Hi,
    Currently we are developing a report on Actuals and Planned sales. We have two different data targets to hold these information.
    CRM team will provide targets for BP monthly in CRM table, from where we are extracting the data into BW and report exection frequency is Daily.
    Report Output format:-
    1)  Target1St Month in the quarter,   Target2nd Month in the quarter, Target3rd Month in the quarter, Target Quarter,  Month To date (Taget for Current month - Sales till today),
    Let us assume we are Q1 and user executing this report on end of March Target1 = Jan, Target2 = Feb, Target 3 = March and Quarter target = Target1 + Target2 + Target 3.
    We can achieve this by offset variables.
    But if users are exectuing this report Apr (Q2) then Target1 = Apr target , target2 and target3 =0
    Becoz we are in Q2 and first month of the quarter. If users are executing this report in May target1 should be Apr target and Target 2 = May target and Target3rd month should be Zero.
    2) We have one keyfigure called as Quarter Phased Target = (Quarter target/ No of weeks in current quarter)* current week; For this we have to get No of weeks in every quarter and Curren week (when the reports get executed).
    Let us assume we are executing this report on 25th jan and target for that month = 122units then Quarter phased target =  [(122 + 0 (For Feb)+ 0 (For Mar) )/ 13] X4
    4 is becoz we are in 4th in that quarter,
    13 is becoz no of weeks in that quarter.
    0 (For Feb) - Becoz we are in Jan only..
    Hence please let me know how to get No of weeks in Current quarter and Current week for every quarter..
    All the helpful answers will be awarded with full points.
    Regards,
    suresh

    hi,
    For the first querry.
    the problem is because u are using calmonth.
    Instead of using cal month use fiscal period.
    When u use fiscal period the data will be shown automatically for the Previous months using offsets.
    u have to take taht in ur transformation and should map it to constant value depending on the fiscal periods of ur compnay?
    march- apr,jan-dec etc.
    for teh second querry there would be some charecteristic which might give data in weeks as well just check that and if availabe u can use it.
    am not too sure abt it.

  • Define months on current quarter

    I successfully created a report with the data of ’current quarter’ and ’last quarter’.
    Now I want to finetune that by adding month 1, month 2, month 3 of these quarters.
    How can this be achieved?
    I support by creating a variable on month, but I do not know how.
    John

    Hi John
    Yes, you can create customer exit variables to populate the data based on month. Get help from ABAP team in your project and do this.
    Alternatively you can also achieve this in infocube level which is easier than customer exit variables. You already have quarter. I am sure you should have calculated it in transformation using some date field. Add calmonth also in the transformation and calculate it in using the same date field.
    Add calmonth also in your report which will give you the output based on month.
    Regards
    Karthik

  • Set date Parameters to Default to Current Quarter

    I have 2 date parameters in my report. I would like these parameters to be defaulted to the 1st day of the current quarter and the last day of the current quarter. I need these to be dafaulted because the report is going to be scheduled through BusinessObjects InfoView. I need the flexabilty to allow users to run the report on any date they want, but it needs to default so the scheduling works as expected. Can this be done and if so any assistance would be grateful. Thank you.

    Thomas,
    although you can't set a prompt / parameter to default like this, you can set a record selection to do this...here's how...
    1) in your StartDate and your EndDate parameters set a default value of 1888,08,08
    2) create a new formula called Start with syntax like
    if {?startdate} = date(1888,08,08)
    then
    if month(currentdate) in [1,2,3] then date(year(currentdate),01,01) else
    if month(currentdate) in [4,5,6] then date(year(currentdate),04,01) else
    if month(currentdate) in [7,8,9] then date(year(currentdate),07,01) else
    if month(currentdate) in [10,11,12] then date(year(currentdate),10,01)
    else {?startdate};
    3) create a new formula called End with syntax like
    if {?enddate} = date(1888,08,08)
    then
    if month(currentdate) in [1,2,3] then date(year(currentdate),03,31) else
    if month(currentdate) in [4,5,6] then date(year(currentdate),06,30) else
    if month(currentdate) in [7,8,9] then date(year(currentdate),09,30) else
    if month(currentdate) in [10,11,12] then date(year(currentdate),12,31)
    else {?enddate};
    4) change your record selection formula to something like
    {table.datefield} in {@start} to {@end}
    now if the end user doesn't actually put in custom dates, the record filter will default to the current quarter. if they use custom dates, the those dates will be used.
    of course you will have to edit the above syntax to your parameter names and datefield name. this method will also pass the filter to the database to increase performance.
    cheers,
    jamie

  • Complete Weeks of current Quarter ..

    Hello,
    we have a time table (exp.: D_TIME) listing every day between 1.1.2006 to 1.1.2017
    and i am triying to filter with following criteria ..
    Complete Weeks of the current Quarter (Only weeks wich are from Monday to Sonday included in the current quarter)
    AND < SYSDATE
    The borders of this Filter are correct but in some days teh result is empty ..
    +
    SELECT * D_TIME
    WHERE
    D_TIME.DATE_X BETWEEN NEXT_DAY(TRUNC(TRUNC(trunc(SYSDATE), 'iw'),'Q')-1,'Monday')
    AND TRUNC(trunc(SYSDATE),'iw')-1
    +
    ANY Suggestions .. ? Thanks ..

    Hi,
    To find all the days between the first Monday in this quarter, and the last Sunday before today, inclusive:
    SELECT  *
    FROM     d_time
    WHERE     date_x    BETWEEN TRUNC ( TRUNC (SYSDATE, 'Q') + 6
                           , 'IW'
                AND       TRUNC (SYSDATE, 'IW') - 1
    ;This assumes that d_time.date_x is always midnight (00:00:00).
    When you TRUNCate a date to some longer time division (such as a quarter),that implies TRUNCating to all smaller divisons that are contained in it, so
    TRUNC (d, 'IW') truncates the hours, minutes and seconds; there's no need to say
    TRUNC (TRUNC (d), 'IW').
    NEXT_DAY is very handy, but it depends on NLS_DATE_LANGUAGE. TRUNC (d, 'IW') works the same regardless of your NLS settings.
    This may still retun 0 rows. For example, as of Sunday, October 9, 2001 there had not been a Monday-to-Sunday week that fell entirely in the current quarter. (The week starting on Monday, Octoeber 3 was not yet complete, by a fraction of a day.)
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.

  • Queries for current Qtr and prior quarter

    If I select one date in dashboard prompt in one column I want to display current quarter revenue and prior Qtr revenue.
    Could anyone give me the queries for the current Qtr and prior Qtr?
    So I will going to use presentation variable from the dashboard prompts

    obiee-date-expressions-reference
    Date Calculation OBIEE Expression Explanation :
    First Day of the Previous Year
    TIMESTAMPADD( SQL_TSI_YEAR , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD removes a year from the returned date for the First Day of the Previous Year.
    First Day of the Current Year
    TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE) This calculation returns the first day of the year by deducting one less than the total number of days in the year.
    First Day of the Next Year
    TIMESTAMPADD( SQL_TSI_YEAR , 1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD adds a year to the date returned which will give the first day of the next year.
    First Day of the Previous Month
    TIMESTAMPADD(SQL_TSI_MONTH, -1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD then subtracts one month from the first day of the Current Month arriving to the First Day of the previous month.
    First Day of the Current Month
    TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE) This expression gets the current day of the month and subtracts one less than the current day to arrive at the first day of the month.
    First Day of the Next Month
    TIMESTAMPADD(SQL_TSI_MONTH, 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD then adds one month from the first day of the Current Month arriving to the First Day of the next month.
    First Day of Current Quarter
    TIMESTAMPADD( SQL_TSI_DAY , DAY_OF_QUARTER( CURRENT_DATE) * -(1) + 1, CURRENT_DATE) This was included to show the calculations discussed above can be used with other functions. This is the same expression as the one that returns the first day of the current month except this one uses the DAY_OF_QUARTER property to return the first day of the current quarter.
    Last Day of the Previous Month
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the Current Month. The second TIMESTAMPADD subtracts a month to arrive at the first day of the previous month.
    Last Day of Current Month
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) From right to left the first TIMESTAMPADD finds the first day of the current Month. The second TIMESTAMPADD adds one month to the date to arrive at the first day of the next month. The final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the Current Month.
    Last Day of the Next Month
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 2, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) From right to left the first TIMESTAMPADD finds the first day of the current Month. The second TIMESTAMPADD adds two months to the date to arrive at the first day of month after next. The final TIMESTAMPADD subtracts one day from the returned date to arrive at the last day of the Next Month.
    Last Day of Previous Year
    TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1,
    CURRENT_DATE)) From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD subtracts one day to arrive at December 31st of the previous year.
    Last Day of Current Year
    TIMESTAMPADD(SQL_TSI_YEAR, 1, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD deducts one day to arrive at December 31 of the previous year. The third TIMESTAMPADD adds a single year to the date to arrive at December 31 of the Current Year.
    Last Day of the Next Year
    TIMESTAMPADD(SQL_TSI_YEAR, 2, TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) From right to left the first TIMESTAMPADD returns the first day of the current year. The second TIMESTAMPADD deducts one day to arrive at December 31 of the previous year. The third TIMESTAMPADD adds 2 years to the date to arrive at December 31 of the Next Year.
    Last Day of Current Quarter
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_QUARTER , 1, TIMESTAMPADD( SQL_TSI_DAY , DAY_OF_QUARTER( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))) Demonstrated using Quarters. From right to left the first TIMESTAMPADD returns the first day of the Current Quarter. The second TIMESTAMPADD returns the first day of the next quarter. The final TIMESTAMPADD subtracts a single day from the date to arrive at the last day of the Current Quarter.
    Number of days between First Day of Year and Last Day of Current Month TIMESTAMPDIFF(SQL_TSI_DAY, CAST('2010/01/01 00:00:00' AS DATE), TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_MONTH , 1, TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)))) For simplicity I hard coded the January 1, 2010 date and CAST it to a date. I could have used the First Day of the Current Year calculation but didn’t want to over clutter the example. The second part of the TIMESTAMPDIFF uses Last Day of the Current Month calculation to force the TIMESTAMPDIFF to calculate the number of days between the first day of the year and the last day of the current month.
    =============
    FYI, let say some example,
    Last day of previous Quarter:
    "GPC_DataMart"."GPC_DataMart"."dbo"."LQ_Position"."Business_Date"=TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAY_OF_QUARTER( "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date") * -(1) + 1, "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date"))
    Last month last day:
    "GPC_DataMart"."GPC_DataMart"."dbo"."LM_Position"."Business_Date"=
    TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date") * -(1) + 1, "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date"))
    Last year Last day
    "GPC_DataMart"."GPC_DataMart"."dbo"."LY_Position"."Business_Date"=
    TIMESTAMPADD( SQL_TSI_DAY , -1, TIMESTAMPADD( SQL_TSI_DAY , EXTRACT( DAY_OF_YEAR FROM "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date") * -(1) + 1, "GPC_DataMart"."GPC_DataMart"."dbo"."MT_BUSINESS_DATE"."Business_Date"))
    Thanks and Regards,
    Deva
    http://obieeelegant.blogspot.com/2011/06/obiee-date-expressions-reference.html

  • Query to find the start and end date of current quarter

    I want a query to give me the start date and end date of current quarter
    I don't want to use TRUNC and ROUND as the 16th day roundoff logic is not required.
    Thanks in advance.

    Hi ,
    I'm quite sure that the year quarters are static.....
    So , you can save them as records of a table , such as:
    QRTY START_DAY END DAY
    ============================
    1 1/1 30/3
    2 1/4 30/6
    3 1/7 30/9
    4 1/10 31/12
    The sysdate(day of the current quarter) must be between a start_day and appropriate end_day of the quarters, concatenated with the sysyear (year of the sysdate).
    So , if the above table is called Quarters ...
    then
    select start_day , end_day
    from quarters
    where to_date(sysdate,'dd/mm/rrrr') between (to_date(trim((start_day||'/'||to_char(sysdate,'rrrr'))),'dd/mm/rrrr'))
    and (to_date(trim((end_day||'/'||to_char(sysdate,'rrrr'))),'dd/mm/rrrr'));
    [b]Result
    START_DAY END_DAY
    1/10 31/12
    Regards,
    Simon
    Message was edited by:
    sgalaxy
    Message was edited by:
    sgalaxy

  • How to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input

    Hi all,
    I need your help how to write customer exit in my BI query to get (current fiscal quarter) and (current fiscal quarter - 1 ) without user input.
    in my query info object is 0CALQUARTER and variable is ZFIS_QTR.
    in 0CALQUARTER fiscal quarter stored in 201301,201302,201303,201304 and 201401 format, for current fiscal quarter 201401 and (current fiscal quarter - 1 ) would be 201304.
    please replay ASAP to deliver the report to client.
    thanks in advance.
    -- Rakesh Nagpure

    I am Getting the same error for both the codes that i have written...
    Do i Need to write sth else in the code...
    Code:
    WHEN 'ZVLIVELEASES'.
      IF I_STEP = 2.
            L_DATE = SY-DATUM.
            SELECT * FROM "DSO_ACTIVE_TABLE"
                INTO TABLE ITAB_LL where "EXPIRY_DATE" > L_DATE.
            LOOP AT ITAB_LL INTO WA_LL.
            CLEAR l_s_range.
            l_s_range-sign = 'I'.
            l_s_range-opt = 'EQ'.
            l_s_range-low = WA_LL-"EXPIRY_DATE".
           APPEND L_S_RANGE TO E_T_RANGE.
            ENDLOOP.
       ENDIF.
    Error: Error for variable in customer enhancement ZLIVELEASES

Maybe you are looking for

  • Make to order Scenario...

    Hi Friends, I have maintained all required fields for make to order scenario..... In MRP 3, Strategy Group- 20 in house production time-  2 days But when I punched sales order , in schedule line tab of order item .....order quantity in getting confir

  • Web Service and Java Classes

    Hello, I have list of java classes. I have one java class which calls only the required functions from the list of java classes. When I try to create a VI on that java class I see all the functions needed but all of them are grayed. Can anybody pleas

  • Fisheye or sphere effect on a bitmap

    Hi folks, I'm hoping someone can help me with this. I know it can be done with text but I'm trying to accomplish it with a bitmap. I want to create what would look like a sphere with a reflection of the Chicago skyline in it. I've created the sphere

  • Why am I missing songs after reorganizing files?

    This morning did everything I usually do but iTunes couldn't locate any song files. So I rebooted and still had the problem. Went to Edit/Preferences and saw that folder location was pointing to the default folder on C:, but my music is on an externa

  • Internet Sharing broken again with 10.6.8 update?

    I have used Internet Sharing for years.  (SysPrefs/Sharing/Internet Sharing/Share your connection from [Ethernet] to computers using [Airport]).  It is very useful in my large old house, where my iMac is connected by an ethernet cable to a WiFi route