Rolling 12 month data

I use the query below to give me summary data for three
categories, for each supplier number, base on a month and year
selection :
<cfquery name="qryGet_NORS" datasource="datasource">
select suplier_number,table2.supplier_name,
sum(case when date_sent is NULL and send_flag is NULL then 1
else 0 end) as cannot_send,
sum(case when date_sent is not NULL then 1 else 0 end) as
total_send,
sum(case send_flag when 'No' then 1 else 0 end) as
total_disapproved
FROM
table1 LEFT JOIN Master_Buyer_Table ON table1.buyer_number =
Master_Buyer_Table.buyer_number
LEFT JOIN table2 ON table1.suplier_number =
table2.supplier_number
where substring(convert(varchar,date_resolved,101), 1, 2) =
'#form.selectmonth#'
and substring(convert(varchar,date_resolved,101), 7, 4) =
'#form.selectyear#'
group by suplier_number,table2.supplier_name
</cfquery>
I then use this QoQ to give me the grand totals for each
supplier number.
<cfquery dbtype="query" name="qryGet_Nors_sum">
select sum(cannot_send) as total_cannot_send,
sum(total_send) as total_total_send,
sum(total_disapproved) as total_total_disapproved
from qryGet_NORS
</cfquery>
What I need to do now is to get and output data for 12
months, starting with the input month and year. For example, if
they enter March 2008, then the above query would give me the three
totals for the period. But now, I need the totals for the next
month, April 2008, then the totals for May 2008, etc, all the way
to March 2009.
How would I modify the query to get all this information
?

First thing is I don't know why you do the following
where substring(convert(varchar,date_resolved,101), 1, 2) =
'#form.selectmonth#'
and substring(convert(varchar,date_resolved,101), 7, 4) =
'#form.selectyear#'
Should be
where Month(date_resolved) = #form.selectmonth#
and Year(date_resolved) = #form.selectyear#
Now for the modification
<!---
So we create a date for the first of the month selected and
return everything that is greater
--->
where date_resolved > #createDate(form.selectYear,
form.selectMonth, 1)#
<!---
To only return one year of data
creatre another date that is one year and one month greater
then return everything smaller
--->
and date_resolved < #createDate(form.selectYear+1,
form.selectMonth+1, 1)#
Ken

Similar Messages

  • Add-On expiry; 30 days or next billing day (rolling 1-month data only contract).

    I'm on a rolling monthly data-only sim/contract. I was running low on my data allowance for this month, so I've added a 10Gb add-on. At each point during the buying process it stated this add-on would expire at my next billing date (about 5 days time) - i.e.even if not used up. However after buying it, the 'thank you' notification and also the subsequent details in 'my account' claim it expires in 30 days (and of course the system is fully aware that my billing day is sooner). It can't be both, and I've found conflicting information when searching for the answer too. I would use the add-on very differently if I had 30 days instead of 5 to use it! Can anyone tell me for sure which it actually is?  CheersKev

    Well its gone past the date my rolling months allowance usually begins on. The good news is that (on this occasion anyway) the addon didn't expire as some parts of the system suggested. Thats assuming by 'billing date' they mean the date of the bill, not the date they subsequently collect payment. Oddly though, the addon is now showing (in 'my account') as 'data left in your plan' rather than as an addon to the plan. And my plan's allowance isn't showing up for this month yet, as if buying the addon has somehow prevented the monthly data contract rolling on (I definately bought an 'add-on', not an 'instead-off'!). So I'm hoping this month's plan is just being queued until the existing addon expires. Which would be completely sensible, but theres nothing (that I can see) to indicate if its the case; currently it looks like there will be nothing left once the small addon runs out. I guess I'll (again) just have to wait to see what actually happens in practice. I'm new to this and so its inevitably a learning curve, but I can't help feel the 'my account' system could be a bit more illuminating :-/ CheersKev

  • Showing last n months data based on prompt

    Hi,
    I have a "reporting month" prompt like Mar'13 .The report should return last 12 months data for all the measures based on "Reporting Month" prompt and my result will look like below:
    Measures  Mar' 13 Feb 13 Jan 13 ....
    CORP        1345     1444     1555
    ERP           675       877       5678
    I have used a pivot view to get the table view like this but i am not sure how to use the logic for showing all Months .Kindly suggest.

    Hi,
    You can achive this at answers level with the help of presentation variable using "Last N months(Rolling months) data By year-month prompt in OBIEE".
    pl follow the below post.
    http://shivabizint.wordpress.com/2008/09/19/rolling-months-data-for-year-month-prompt-in-obiee/
    thanks

  • Rolling 13 months data dynamically

    Hi All ,
    I got the 'Cal year/Month' filed  and it is showing as 04.2010.
    How to make the block to get rolling 13 months data and how to make the block dynamic.
    Could any one please help me on this and how to convert the data 04.2010 to April 2010.
    Many Thanks in advance

    In the first column of the block get the current month data and then add second column for last month data by creating an report level object with the following formula.
    =If(MonthNumberOfYear(CurrentDate()) =1;ToDate("12/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy" ); ToDate(FormatNumber(MonthNumberOfYear(CurrentDate())-1;"##")"/01/"FormatNumber(Year(CurrentDate());"####");"MM/dd/yyyy") )
    Similarly, add another column for 'last month - 1' data by creating an report level object with following formula.
    = If(MonthNumberOfYear(CurrentDate()) =2;ToDate("12/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy"); If(MonthNumberOfYear(CurrentDate()) =1;ToDate("11/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy" ); ToDate(FormatNumber(MonthNumberOfYear(CurrentDate())-2;"##")"/01/"FormatNumber(Year(CurrentDate());"####");"MM/dd/yyyy") ) )
    Similarly, add another column for 'last month - 2' data by creating an report level object with following formula.
    = If(MonthNumberOfYear(CurrentDate()) =3;ToDate("12/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy"); If(MonthNumberOfYear(CurrentDate()) =2;ToDate("11/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy"); If(MonthNumberOfYear(CurrentDate()) =1;ToDate("10/01/"+ FormatNumber(Year(CurrentDate())-1;"####"); "MM/dd/yyyy" ); ToDate(FormatNumber(MonthNumberOfYear(CurrentDate())-3;"##")"/01/"FormatNumber(Year(CurrentDate());"####");"MM/dd/yyyy") ) ) )
    In a similar fashion continue this logic for last month -10. This will give you the block of rolling 13 months data.
    In the case of date function. If your date is a DATE data type then use FormatDate() or if its a STRING data type then use SubStr.
    Thanks,
    Praneeth

  • Dynamically rolling months forward in Analyzer with HFM data source

    I'm building a dashboard in Analyzer 7.0. I want the reports to dynamically update each month so a user does not have to go in and change the month on each report. Normally I would use a sub variable (i.e. cur_month) however, the datasource is not Essbase, it's HFM.Anyone else using HFM as a data source and found a feesible way to roll months forward in Analyzer after the close? I looked at Personal variables, but that still leaves me with the same problem of someone having to go in and update each users personal variables.Suggestions are appreciated as well.Thanks,Gary CrisciSenior ConsultantPinnacle Group, [email protected]

    I came up with a working solution. Analyzer allows you to retreive member lists from HFM. I created a member list called 'Current Month' and assigned a single member to it. I then pull the report using the member list and get the current month view. Now the admin only has to update the meber list once a month when the close is finished and all reports will "Dynamically" roll forward.Regards,

  • 5 months rolling monthly report by fetching data from cache & Database

    Scenario: One monthly report would be created each month end which contains one summary tab and other details tabs. Summary tabs will contain the data of all the months summary data (current month and previous months)
    Problem:
    Current month data have to come directly from database and previous months data come form cache and whole thing will be cached this time so that when we run next month report the data till this month will also come from cache.
    Any one please help me ASAP.

    What's wrong with F_GET_COMPANY_CODE ?  Below is similar code - try running this and seeing what you get:
    report zlocal_jc_t001w.
    tables:
      t001k,     "Valuation area
      t001w.     "Plants/Branches
    parameters:
      p_bukrs          like t001k-bukrs default '1000'.
    select-options:
      s_werks          for t001w-werks.
    start-of-selection.
      perform get_data.
    *&      Form  get_data
    form get_data.
      data:
        begin of gt_t001k occurs 10,
          bukrs             like t001k-bukrs,
          bwkey             like t001k-bwkey,
          werks             like t001w-werks,
        end of gt_t001k.
      select
        t001k~bukrs
        t001k~bwkey
        t001w~werks
        into corresponding fields of table gt_t001k
        from t001k as t001k
        inner join t001w as t001w on t001w~bwkey = t001k~bwkey
        where t001k~bukrs = p_bukrs
        and   t001w~werks in s_werks.
      loop at gt_t001k.
        write: /
          gt_t001k-bukrs,
          gt_t001k-bwkey,
          gt_t001k-werks.
      endloop.
    endform.                    "get_data
    As for links to locally defined database tables, that will depend on what the keys defined in SE11 are e.g. there will be a primary key plus relationships to other tables (for example "WERKS LIKE YSDA_EXP_PRTLOG-YY_PLANT" indicates YY_PLANT relates to T001W).
    Jonathan

  • Rolling month at repot level

    Is it possible to adding rolling 12 month at the report level? Does a formula need to be added or is there is an example I can see. I saw an example where the rolling months can be entered by the user but in this case th the # of monts need to be 12.
    Thank you

    suser,
    In the report add the below filter condition
    u can replace 6 with 12 incase of 12 months
    if u want to use max date available in database instead of current_Date ,create a rep variable which ll give u max(report_Date) use that in formula
    timestampdiff(slq...... , -12, valueof(rep_Var) and valueof(rep_var)
    http://img4.imageshack.us/img4/8607/filtersh.jpg

  • Rolling Months

    I created 12 rolling session variables to use to get 12 month rolling sums for my report. After creating the variables i made this filter to get sums for my GL balances (12 months ending).
    FILTER ("Facts - GL Balance"."Balance Amount") USING ("Time"."Fiscal Period End Date" BETWEEN VALUEOF(NQ_SESSION.PERIOD_START_11AGO) and VALUEOF(NQ_SESSION.PERIOD_END_00))
    this filter works only for 12 periods from the current date (NQ_SESSION.PERIOD_END_00) - how can I expand my range to include all the fiscal periods from 2002 to 2011, right now the report only gives me 12 periods from 10/31/2011 to 11/30/2010... for some reason my filter is limiting me, how can i circumvent this.... any help wld be apprceiated!!!!

    Thank you Deepak, you guided me correctly it is working for my 12/31 end of month dates bcoz it is rolling summed months from january. All other dates when selected from droplist are a sum from jan and not 12 months ago, i did all teh steps how can i now make the data correct- thanks
    Edited by: 846431 on Nov 2, 2011 9:21 AM

  • Rolling Month in Billing Plan in Sales Order

    I Require rolling month billing dates in Sales Orders . Kindly help on the same the followng format is required.
    Contract Start Date : 05.01.2010
    Contract End Date : 31.03.2010
    Settlement From   Settlement to    Billing Date
    05.01.2010            04.02.2010     04.02.2010
    05.02.2010            04.03.2010     04.03.2010
    05.03.2010            31.03.2010     31.03.2010.
    If there are any user exits where i can make these changes or if there are any configurations that i  can change then suggest.
    Thanx in Advance.
    Dilip

    You have to enable the PERIODIC BILLING as the billing plan for your case.
    You can refer to the OSS note 831158 which gives lot of other OSS notes for you to configure the scenario.

  • Team calendar - rolling month

    Hi all
    Just wondering if anyone has found a way to have the team calendar show a rolling month i.e. rather than a static month (1 - 31), show 15 days prior to todays date and 15 days after todays date.
    Our managers get annoyed towards the end of the month as they have to continuously change between the current and next month in order to see if people are at work (we run a fortnightly payroll, not monthly).
    Any feedback would be appreciated.
    PS

    Nachy,
    All of these have start dates in 2009, whereas, we can't see data for previous months in 2010. I believe the relationship I mentioned in the initial post is responsible, even though there are enteries before it that are ignored.
    We just discovered this and we are live. (i.e. this is production environment) Your prompt replies will be highly appreciated.
    Regards,
    Motaz

  • Issue with Past Month data in the Select Statement

    Hi,
    I written the following query,
    SELECT   /*+NO_MERGE(A)*/
                CASE
                   WHEN snap_shot_date > a.q3
                   AND snap_shot_date <= a.q4
                      THEN q4char
                   WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
                      THEN q3char
                   WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
                      THEN q2char
                   WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
                      THEN q1char              
                END snap_shot_date,
                CASE
                   WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
                      THEN 1
                   WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
                      THEN 2
                   WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
                      THEN 3
                   WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
                      THEN 4
                END sort_by,
                pillar3_exposure_class_code, pd_band_description,
                ROUND (SUM (p3.ead_post_sec_post_crm)),
                ROUND (SUM (notional_principle)),
                DECODE (SUM (notional_principle),
                        0, 0,
                        ROUND (  SUM (DECODE (exposure_type,
                                              'UNDRAW', ead_post_sec_post_crm,
                                              0
                               / SUM (notional_principle),
                               4
                DECODE (SUM (p3.ead_post_sec_post_crm),
                        0, 0,
                        ROUND (  SUM (pd_value * p3.ead_post_sec_post_crm)
                               / SUM (p3.ead_post_sec_post_crm),
                               2
                DECODE (SUM (p3.ead_post_sec_post_crm),
                        0, 0,
                        ROUND (SUM (rwa) / SUM (p3.ead_post_sec_post_crm), 4)
                DECODE (SUM (p3.ead_post_sec_post_crm),
                        0, 0,
                        ROUND (  SUM (lgd_rate * p3.ead_post_sec_post_crm)
                               / SUM (p3.ead_post_sec_post_crm),
                               2
                TO_CHAR (MAX (a.max_date), 'FMMonth DD, YYYY')
           FROM summary.pillar3 p3,
                (SELECT DISTINCT (month_end_date) max_date,
                                 LAST_DAY (month_end_date) q4,
                                 TO_CHAR (LAST_DAY (month_end_date),
                                          'MON YYYY'
                                         ) q4char,
                                 ADD_MONTHS (LAST_DAY (month_end_date), -3) q3,
                                 TO_CHAR
                                    (ADD_MONTHS (LAST_DAY (month_end_date), -3),
                                     'MON YYYY'
                                    ) q3char,
                                 ADD_MONTHS (LAST_DAY (month_end_date), -6) q2,
                                 TO_CHAR
                                    (ADD_MONTHS (LAST_DAY (month_end_date), -6),
                                     'MON YYYY'
                                    ) q2char,
                                 ADD_MONTHS (LAST_DAY (month_end_date), -9) q1,
                                 TO_CHAR
                                    (ADD_MONTHS (LAST_DAY (month_end_date), -9),
                                     'MON YYYY'
                                    ) q1char,
                                 ADD_MONTHS (LAST_DAY (month_end_date), -12) q0
                            FROM rcdwstg.stg_bcar_detail) a
          WHERE snap_shot_date BETWEEN ADD_MONTHS (a.max_date, -12) AND a.max_date
       GROUP BY CASE
                   WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
                      THEN q4char
                   WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
                      THEN q3char
                   WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
                      THEN q2char
                   WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
                      THEN q1char
                END,
                CASE
                   WHEN snap_shot_date > a.q3 AND snap_shot_date <= a.q4
                      THEN 1
                   WHEN snap_shot_date > a.q2 AND snap_shot_date <= a.q3
                      THEN 2
                   WHEN snap_shot_date > a.q1 AND snap_shot_date <= a.q2
                      THEN 3
                   WHEN snap_shot_date > a.q0 AND snap_shot_date <= a.q1
                      THEN 4
                END,
                pillar3_exposure_class_code,
                pd_band_description
       ORDER BY 2 DESC;I have written the query to get the latest 12 months data from a table and split that into 4 quarter to show in the Cognos Report. But when the table having 13th or the past months data, the select statement is showing Empty values in the first two columns and fetching the 13 month data too.
    Can anyone help me in this to avoid the problem.
    Thanks
    Radha K

    WHERE snap_shot_date BETWEEN ADD_MONTHS(TRUNC(a.max_date, 'MM'), -11) AND  a.max_date
    ....

  • Is it possible to post the Excise invoice previous month date.

    Dear All,
    We want to post a excise invoice with previous month date. Is that possible?
    We have created a billing document (VF01) last month (October) and not created Excise Invoice (J1IIN).
    Now our finance people requirement is to create the excise invoice with last month date.
    Kindly let me know whether it is possible.
    Regards,
    Mullairaja

    Yes quite possible provided your FI period is still open.  Once you execute J1IIN and clicked the tab "Billing", you can see a field Posting Date where you maintain the billing document date itself if FI period is open.
    But from excise point of view, this is wrong due to the fact that excise returns should be submitted on or before 3rd of every month in which case, the excise team would have submitted the returns for October.
    thanks
    G. Lakshmipathi

  • Need a formula for 12 months data, 6 months data and 3 month

    Hi All Crystal Experts,
    In my report, data is grouped by months and I have monthly view of data. I have three prompts- Year, Startdate and Enddate. If I give 2013 as year, 1/1/2013 as start date and 05/01/2013 as end date then report shows monthly view of data for Jan-13, feb-13, Mar13, Apr-13 and May-13. Now in report, for each month, I want three additional columns, I want to show last 12month, 6 month and 3 months view. Like for Jan-13 month, in column 6 months, I want to show data for last 5 months including current month i.e. Jan-13+Dec-12+Nov-12+Oct-12+Sep-12+Aug-12 and in Column 12months view, I want to show accumulated data of last 11 months(+ current month) and in 3 months view, data for last 2 months(+ current month).
    I had tried creating Sub report for 12 months view and created Running total formula  but it is not showing any value in report. It is blank. I have created running total like this way:
    (1) "Running total formula" (which I am using and placing on group footer):
    (I) Field to summarize- @Cash_total
    (ii) Evaluate (use a formula):
    WhilePrintingRecords;
    NumberVar Cash_total_12 months;
    If Month ({@Month_PostDate}) In [(Month {?StartPostDate} - 11) to Month
    {?StartPostDate}] Then
       Cash_total_12 months :=  Cash_total_12 months + {@Cash_Total};
    (iii) Reset (use a formula):
    WhilePrintingRecords;
    NumberVar Cash_total_12 months=0;
    When I placed this formula in group footer, it is showing nothing.
    Please suggest me formula. Quick help would be much appreciated.
    Thanks,

    Hi Remi,
    Please do not post multiple threads for the same issue.
    Continue discussion on this thread:
    How to calculate last 12 months, 6 months, 3 months data in report
    -Abhilash

  • How to show a report for 'Previous Month' Data

    Hi Gurus,
    I have a requirement, where i have to default my report to show previous month data.
    Scenario:
    My prompts by Default are set to CURRENT (current year,quarter,month). once the user logs in, the report should display data for month 'Nov' instead of 'Dec'.
    I tried using TIMESTAMPADD() in the formula , but it didn't work, though i don't see any error. Not sure if i 'm missing something.
    Is there a way to achieve this.I 'm using OBIEE 11.1.1.6.
    Any help is highly Appreciated ! Please.
    Thanks,
    Ramya

    From what you wrote I am assuming the user can manually save the report results to the Excel file.
    If your report uses ALV Grid it is possible to export the data to a spreadsheet (one of the functions available in the ALV tool bar).
    If you have used WRITE statements it is also possible to save the output as a spreadsheet (menu System -> List -> Save), but the latter will not produce as nice a spreadsheet if the data don't form a matrix. In other words, some work may be necessary in the spreadsheet afterwards before it has the format your user wants.

  • Calendar month dates in horizontal line

    Is there anyway to show calendar month dates in horizontal line?
    First line will have dates and then second line will have day i.e Sat, Sun, Mon.......
    1 2 3 4 5 6 7 8 9 ........31

    orion_123 wrote:
    Is there anyway to show calendar month dates in horizontal line?
    First line will have dates and then second line will have day i.e Sat, Sun, Mon.......
    1 2 3 4 5 6 7 8 9 ........31You can do all sorts of things if you put your mind to it... e.g.
    SQL> break on month skip 1
    SQL> set linesize 200
    SQL> set pagesize 2000
    SQL> column month format a20
    SQL> column week format a4
    SQL> with req as (select '&Required_Year_YYYY' as yr from dual)
      2      ,offset as (select case when to_char(trunc(to_date(yr,'YYYY'),'YYYY'),'IW') in ('52','53') then 1 else 0 end as offset from req)
      3  select lpad( Month, 20-(20-length(month))/2 ) month,
      4         '('||week||')' as week, "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"
      5  from (
      6    select to_char(dt,'fmMonth YYYY') month,
      7    case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
      8         when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
      9         when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    10         else to_char(to_number(to_char(dt,'iw'))+offset) end as week,
    11    max(decode(to_char(dt,'d'),'1',lpad(to_char(dt,'fmdd'),2))) "Mo",
    12    max(decode(to_char(dt,'d'),'2',lpad(to_char(dt,'fmdd'),2))) "Tu",
    13    max(decode(to_char(dt,'d'),'3',lpad(to_char(dt,'fmdd'),2))) "We",
    14    max(decode(to_char(dt,'d'),'4',lpad(to_char(dt,'fmdd'),2))) "Th",
    15    max(decode(to_char(dt,'d'),'5',lpad(to_char(dt,'fmdd'),2))) "Fr",
    16    max(decode(to_char(dt,'d'),'6',lpad(to_char(dt,'fmdd'),2))) "Sa",
    17    max(decode(to_char(dt,'d'),'7',lpad(to_char(dt,'fmdd'),2))) "Su"
    18    from ( select trunc(to_date(req.yr,'YYYY'),'y')-1+rownum dt
    19           from all_objects, req
    20           where rownum <= add_months(trunc(to_date(req.yr,'YYYY'),'y'),12) - trunc(to_date(req.yr,'YYYY'),'y') )
    21        ,offset
    22    group by to_char(dt,'fmMonth YYYY'),     case when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 0 then '53'
    23                                                  when to_char(dt, 'mm') = '12' and to_char(dt,'iw') = '01' and offset = 1 then '54'
    24                                                  when to_char(dt, 'mm') = '01' and to_char(dt,'iw') in ('52','53') then '1'
    25                                                  else to_char(to_number(to_char(dt,'iw'))+offset) end
    26    ) x
    27  order by to_date( month, 'Month YYYY' ), to_number(x.week)
    28  /
    Enter value for required_year_yyyy: 2012
    old   1: with req as (select '&Required_Year_YYYY' as yr from dual)
    new   1: with req as (select '2012' as yr from dual)
    MONTH                WEEK Mo Tu We Th Fr Sa Su
        January 2012     (1)                     1
                         (2)   2  3  4  5  6  7  8
                         (3)   9 10 11 12 13 14 15
                         (4)  16 17 18 19 20 21 22
                         (5)  23 24 25 26 27 28 29
                         (6)  30 31
       February 2012     (6)         1  2  3  4  5
                         (7)   6  7  8  9 10 11 12
                         (8)  13 14 15 16 17 18 19
                         (9)  20 21 22 23 24 25 26
                         (10) 27 28 29
         March 2012      (10)           1  2  3  4
                         (11)  5  6  7  8  9 10 11
                         (12) 12 13 14 15 16 17 18
                         (13) 19 20 21 22 23 24 25
                         (14) 26 27 28 29 30 31
         April 2012      (14)                    1
                         (15)  2  3  4  5  6  7  8
                         (16)  9 10 11 12 13 14 15
                         (17) 16 17 18 19 20 21 22
                         (18) 23 24 25 26 27 28 29
                         (19) 30
          May 2012       (19)     1  2  3  4  5  6
                         (20)  7  8  9 10 11 12 13
                         (21) 14 15 16 17 18 19 20
                         (22) 21 22 23 24 25 26 27
                         (23) 28 29 30 31
         June 2012       (23)              1  2  3
                         (24)  4  5  6  7  8  9 10
                         (25) 11 12 13 14 15 16 17
                         (26) 18 19 20 21 22 23 24
                         (27) 25 26 27 28 29 30
         July 2012       (27)                    1
                         (28)  2  3  4  5  6  7  8
                         (29)  9 10 11 12 13 14 15
                         (30) 16 17 18 19 20 21 22
                         (31) 23 24 25 26 27 28 29
                         (32) 30 31
        August 2012      (32)        1  2  3  4  5
                         (33)  6  7  8  9 10 11 12
                         (34) 13 14 15 16 17 18 19
                         (35) 20 21 22 23 24 25 26
                         (36) 27 28 29 30 31
       September 2012    (36)                 1  2
                         (37)  3  4  5  6  7  8  9
                         (38) 10 11 12 13 14 15 16
                         (39) 17 18 19 20 21 22 23
                         (40) 24 25 26 27 28 29 30
        October 2012     (41)  1  2  3  4  5  6  7
                         (42)  8  9 10 11 12 13 14
                         (43) 15 16 17 18 19 20 21
                         (44) 22 23 24 25 26 27 28
                         (45) 29 30 31
       November 2012     (45)           1  2  3  4
                         (46)  5  6  7  8  9 10 11
                         (47) 12 13 14 15 16 17 18
                         (48) 19 20 21 22 23 24 25
                         (49) 26 27 28 29 30
       December 2012     (49)                 1  2
                         (50)  3  4  5  6  7  8  9
                         (51) 10 11 12 13 14 15 16
                         (52) 17 18 19 20 21 22 23
                         (53) 24 25 26 27 28 29 30
                         (54) 31
    64 rows selected.
    SQL>That's just an example, but yes, of course you can do it. Oracle provides excellent DATE functionality.

  • Return Current month Data:Help needed in modifying this code of a Procedure

    Hello Folks i have this scenario where i need to modify this code so that it has to return data from the Current month First Day to the previous Day if its a daily report and previous month data if its a monthly report.
    I have no clue how to modify this code below. Currently the code is returning data for Monthly reports for the previous month. Does anyone have any idea how to modify so that the code meets the requirements of both daily and monthly reprts.
    BEGIN
    if v_lowdate is null or v_highdate is null then
    select to_number(to_char(sysdate, 'DD')) into v_cur_day from dual;
    if v_cur_day < 25 then
    -- this is for the previous month run
    Select Add_Months(trunc(sysdate, 'MONTH'), -1)
    INTO V_LOWDATE
    FROM DUAL;
    SELECT Last_Day(ADD_Months(Sysdate, -1)) INTO V_Highdate From Dual;
    else
    -- this is for the current month run
    Select trunc(sysdate, 'MONTH') INTO V_LOWDATE FROM DUAL;
    SELECT Last_Day(Sysdate) INTO V_Highdate From Dual;
    end if;
    end if;
    Thanks
    Edited by: user11961230 on Sep 30, 2009 8:34 PM

    Hi Frank, This is code till the "modifying Code" which we were working. I will post the code after the "modifying Code" in the next reply. Thanks
    CREATE OR REPLACE PROCEDURE "POPULATE_RECOVERY_ACTIVITYHN"(p_lowdate date,
    p_highdate date) IS
    v_lowdate date := p_lowdate;
    v_highdate date := p_highdate;
    v_error_code NUMBER(20);
    v_error_text VARCHAR2(300);
    v_recovery_id Recovery.Recovery_ID%type;
    v_loop_control Number(20);
    v_settlement_id recovery.settlement_id%type;
    V_Event_ID Event.Event_ID%Type;
    V_Event_Case_ID Event_Case.Event_Case_ID%Type;
    V_Recovery_Month Varchar2(100);
    V_Major_Company Major_Client.Major_Client_Name%Type;
    V_Company Client.Client_Name%Type;
    V_Client_Policy_Identifier Varchar2(100);
    V_Lan_ID Varchar2(10) := 'TROVERIS';
    V_Recovery_Account Client.Account_Number%Type;
    V_AccountA Number(2) := 0;
    V_AccountB Number(2) := 0;
    V_Unit Event_Client_Field.Client_Field_Data%Type;
    V_Market Event_Client_Field.Client_Field_Data%Type;
    V_case_open_date Event_case.Open_Date%type;
    V_Employer_Group_Code Employer_Group.Employer_Group_Code%Type;
    V_Unknown1 Number(2) := 0;
    V_Fee_Schedule_Code Event_Case.Fee_Schedule_Code%Type;
    V_Total_Fee_Percent Number(20, 2) := 0.00;
    V_Subrogation_Fee_Percent Number(20, 2) := 0.00;
    V_Unknown2 Number(2) := NULL;
    V_Unknown3 Number(2) := NULL;
    V_TOTAL_MEDICAL Number(20, 2) := 0.00;
    V_Recovery_Amount Number(20, 2) := 0.00;
    V_Total_Tax Number(20, 2) := 0.00;
    V_Administrative_Tax Number(20, 2) := 0.00;
    V_Total_NonCash_Fee Number(20, 2) := 0.00;
    V_Total_NonCash_Positive Number(20, 2) := 0.00;
    V_Total_NonCash_Negative Number(20, 2) := 0.00;
    V_Total_Recovery Number(20, 2) := 0.00;
    V_Total_NonCash_Fee_Positive Number(20, 2) := 0.00;
    V_Total_NonCash_Fee_Negative Number(20, 2) := 0.00;
    V_Total_Admin_Fee Number(20, 2) := 0.00;
    V_Total_Fee Number(20, 2) := 0.00;
    V_Total_NonCash_Tax_Positive Number(20, 2) := 0.00;
    V_Total_NonCash_Tax_Negative Number(20, 2) := 0.00;
    report_type                  Varchar2(2);
    v_gl_num client.gl_num%type; -- *002*
    v_net_billable client.net_billable%type; -- *003*
    vevent_id event.event_id%type; -- *006*
    v_prev_event event.event_id%type; -- *006*
    v_prev_case event_case.event_case_id%type; -- *006*
    v_tot_recovery recovery.amount%type; -- *006*
    v_rec_amount recovery.amount%type; -- *006*
    v_prev_rec_amt recovery.amount%type; -- *006*
    v_prev_rec_month recovery_activity.recovery_month%type; -- *006*
    v_tot_fee recovery_activity.total_fee%type; --*006*
    v_mth_rev unbundled_recoveries.monthly_revenue%type; -- *006*
    v_diff number(18, 2); -- *006*
    v_nc_count number := 0; -- *006*
    v_c_count number := 0; -- *006*
    v_nc_tot recovery.amount%type; -- *006*
    v_used_rev recovery_activity.total_fee%type; -- *006*
    v_use_mth_rev unbundled_recoveries.monthly_revenue%type := 0; -- *006*
    v_use_nc_mth_rev unbundled_recoveries.monthly_revenue%type := 0; -- *006*
    v_prev_netbill client.net_billable%type; -- *006*
    v_event_type event.event_type_code%type;
    v_date_typed event.date_typed%type;
    v_acc_client_id client.acc_client_id%Type;
    v_Recovery_Revenue_GL_Num client.recovery_revenue_gl_num%Type;
    v_Funds_Due_GL_num client.funds_due_gl_num%Type;
    v_lob Varchar2(20);
    v_nc_recovery_id recovery.recovery_id%Type;
    /*Changed the Client_Policy_Identifier to concatenate the Retlation to insured code instead of the description
    which was exceeding the column size in the table. SWL 09/03/02. Checked with the Design Doc.*/
    CURSOR RECOVERY_INFO IS
    SELECT Event.Event_ID,
    Event_Case.Event_Case_ID,
    TO_CHAR(Recovery.Recovery_Date, 'FMMONTHYYYY') As Recovery_Month,
    Major_Client.Major_Client_Name AS Major_Company,
    -- Client.Client_Name AS Company,
    -- nvl(client.legacy_client_id,'DC')||'-'||substr(Client.Client_Name,1,55) AS Company, -- SWL 04/01/04 52653
    substr(nvl(client.legacy_client_id,
    decode(client.client_id, 1, 'DC', client.client_code)) || '-' ||
    Client.Client_Name,
    1,
    60) AS Company,
    Event.Client_Policy_Identifier ||
    Event_Case.Relation_To_Insured_code as Client_Policy_Identifier,
    Client.Account_Number as Recovery_Account,
    Employer_Group.Employer_Group_Code,
    Event_Case.Fee_Schedule_Code,
    Recovery_ID,
    Event_case.Open_Date,
    '(' || recovery.recovery_transaction_internal || ')' ||
    l.recovery_transaction_descripti, --fml 110276
    recovery.settlement_id,
    trim(client.gl_num), -- *002*
    nvl(trim(client.net_billable), 'N'), -- *003*
    recovery.amount, -- *006*,
    event.event_type_code,
    event.date_typed,
    recovery_id,
    Client.ACC_CLIENT_ID,
    Recovery_Revenue_GL_Num,
    Funds_Due_GL_num
    FROM Recovery,
    Settlement,
    Event_Case,
    Event,
    Employer_Group,
    Client,
    Major_Client,
    recovery_transaction_lookup l
    Where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    AND Settlement.Settlement_id = Recovery.Settlement_id
    AND Settlement.Event_Case_ID = Event_Case.Event_Case_id
    AND Event_Case.Event_ID = Event.Event_ID
    AND Event.Employer_Group_ID = Employer_Group.Employer_Group_ID(+)
    AND Event.Client_ID = Client.Client_ID
    AND Client.Major_Client_id = Major_Client.Major_Client_ID(+)
    and recovery.settlement_id not in
    (select settlement_id
    from recovery
    where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    AND recovery_transaction_internal in
    ('05', '50', '52', '51'))
    --001
    and    client.invoice_flag = 'N'            *005* commenting
    -- SWL 05/03/05 #71231
    and event.event_id in
    (select event_id
    from event_end_user eeu
    where eeu.active_flag = 'Y'
    and eeu.owner_flag = 'Y'
    and eeu.end_user_id in
    (select end_user_id
    from end_user
    where end_user.research_internal_user = 'Y'))
    and recovery.recovery_transaction_internal =
    l.recovery_transaction_internal --fml 110276
    order by event.event_id, recovery.amount; -- *006*
    -- SWL 05/03/05 #71231
    -- end of 001
    -- SWL 11/10/03 # 52743
    -- *006*
    CURSOR get_recovery(vevent_id event.event_id%type) IS
    SELECT sum(r.amount)
    FROM Recovery r
    Where to_date(r.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    and r.event_id = vevent_id
    and r.settlement_id not in
    (select settlement_id
    from recovery
    where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    AND recovery_transaction_internal in
    ('05', '50', '52', '51'))
    and r.event_id in
    (select event_id
    from event_end_user eeu
    where eeu.active_flag = 'Y'
    and eeu.owner_flag = 'Y'
    and eeu.end_user_id in
    (select end_user_id
    from end_user
    where end_user.research_internal_user = 'Y'));
    CURSOR RECOVERY_INFO_NC IS
    SELECT distinct Event.Event_ID,
    Event_Case.Event_Case_ID,
    TO_CHAR(Recovery.Recovery_Date, 'FMMONTHYYYY') As Recovery_Month,
    Major_Client.Major_Client_Name AS Major_Company,
    -- Client.Client_Name AS Company,
    -- nvl(client.legacy_client_id,'DC')||'-'||substr(Client.Client_Name,1,55) AS Company, /* SWL 04/01/04 52653 */
    substr(nvl(client.legacy_client_id,
    decode(client.client_id,
    1,
    'DC',
    client.client_code)) || '-' ||
    Client.Client_Name,
    1,
    60) AS Company,
    Event.Client_Policy_Identifier ||
    Event_Case.Relation_To_Insured_code as Client_Policy_Identifier,
    Client.Account_Number as Recovery_Account,
    Employer_Group.Employer_Group_Code,
    Event_Case.Fee_Schedule_Code,
    '(' || recovery.recovery_transaction_internal || ')' ||
    l.recovery_transaction_descripti, --fml 110276
    recovery.settlement_id,
    trim(client.gl_num), -- *002*
    nvl(trim(client.net_billable), 'N'), -- *003*
    recovery.amount,-- *006*
    recovery.recovery_id,
    event.event_type_code,
    event.date_typed,
    Client.ACC_CLIENT_ID,
    Recovery_Revenue_GL_Num,
    Funds_Due_GL_num
    FROM Recovery,
    Settlement,
    Event_Case,
    Event,
    Employer_Group,
    Client,
    Major_Client,
    recovery_transaction_lookup l
    Where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    AND Settlement.Settlement_id = Recovery.Settlement_id
    AND Settlement.Event_Case_ID = Event_Case.Event_Case_id
    AND Event_Case.Event_ID = Event.Event_ID
    AND Event.Employer_Group_ID = Employer_Group.Employer_Group_ID(+)
    AND Event.Client_ID = Client.Client_ID
    AND Client.Major_Client_id = Major_Client.Major_Client_ID(+)
    and recovery.settlement_id in
    (select settlement_id
    from recovery
    where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    --001
    AND recovery.recovery_transaction_internal in
    ('05', '50', '52', '51')
    and    client.invoice_flag = 'N'   *005* commenting
    /* SWL 05/03/05 #71231 */
    and event.event_id in
    (select event_id
    from event_end_user eeu
    where eeu.active_flag = 'Y'
    and eeu.owner_flag = 'Y'
    and eeu.end_user_id in
    (select end_user_id
    from end_user
    where end_user.research_internal_user = 'Y'))
    and recovery.recovery_transaction_internal =
    l.recovery_transaction_internal --fml 110276
    order by event.event_id, recovery.amount; -- *006*
    /* SWL 05/03/05 #71231 */
    --end of 001
    -- *006*
    CURSOR get_recovery_nc(vevent_id event.event_id%type) IS
    SELECT sum(r.amount)
    FROM Recovery r
    Where to_date(r.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR')
    AND r.event_id = vevent_id
    and r.settlement_id in
    (select settlement_id
    from recovery
    where to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR'))
    AND recovery_transaction_internal in ('05', '50', '52', '51')
    and r.event_id in
    (select event_id
    from event_end_user eeu
    where eeu.active_flag = 'Y'
    and eeu.owner_flag = 'Y'
    and eeu.end_user_id in
    (select end_user_id
    from end_user
    where end_user.research_internal_user = 'Y'));
    CURSOR Recovery_Totals_Nc IS
    Select Recovery_Detail.Recovery_Id, /* SWL 07/01/04 59016 */
    max(NVL(Recovery_Detail.Fees_Percent, 0) +
    NVL(Recovery_Detail.Admin_Percent, 0)) as Total_Fee_Percent,
    max(NVL(Recovery_Detail.Fees_Percent, 0)) as Subrogation_Fee_Percent,
    max(NVL(Recovery.Amount, 0)) as Recovery_Amount, /* SWL 04/01/04 52653 */
    Sum(NVL(Recovery_detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_Fee,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_Tax,
    Sum(NVL(Recovery_Detail.Admin_Taxes, 0)) as Administrative_tax,
    Sum(NVL(Recovery_Detail.Admin, 0)) as Total_Admin_Fee,
    sum(recovery.retained_by_client) as Non_cash_fee, --fml 110276
    sum(recovery.allocation_check_amount) as cash --fml 110276
    From Settlement, Recovery, Recovery_Detail
    Where Recovery.settlement_id = v_settlement_id
    And recovery.recovery_id = v_recovery_id
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    and to_date(Recovery.Recovery_Date, 'DD-MON-RR') between
    TO_DATE(v_lowdate, 'DD-MON-RR') and
    TO_DATE(v_highdate, 'DD-MON-RR') /*SWL 12/03/04 */
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    Group by Recovery_Detail.recovery_id;
    v_cash_recovery recovery_activity.cash_recovery%type;
    CURSOR Recovery_Totals_Positive_Nc IS
    -- Select Sum(Recovery.Amount) as Total_NonCash_Positive, /* SWL 04/01/04 52653 */
    Select max(Recovery.Amount) as Total_NonCash_Positive,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Positive
    From Settlement, Recovery, Recovery_detail
    Where Recovery.settlement_id = v_settlement_id
    And Settlement.Settlement_id = Recovery.Settlement_id
    and recovery.recovery_id = v_recovery_id /* SWL 07/01/04 59016 */
    And Recovery.Amount >= 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in
    ('05', '50', '52', '51')
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    Group by Recovery_Detail.recovery_id;
    CURSOR Recovery_Totals_Negative_Nc IS
    -- Select Sum(Recovery.Amount) as Total_NonCash_Negative, /* SWL 04/01/04 52653 */
    Select max(Recovery.Amount) as Total_NonCash_Negative,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Negative
    From Settlement, Recovery, Recovery_Detail
    Where Recovery.settlement_id = v_settlement_id
    And Settlement.Settlement_id = Recovery.Settlement_id
    and recovery.recovery_id = v_recovery_id /* SWL 07/01/04 59016 */
    And Recovery.Amount < 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in
    ('05', '50', '52', '51')
    Group by Recovery_Detail.recovery_id;
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    /* SWL 11/10/03 # 52743 */
    CURSOR Event_Client_Unit IS
    Select e.Client_Field_Data as Unit
    From Event_Client_Field e, recovery r
    Where r.Event_ID = e.Event_ID
    AND r.Recovery_ID = V_Recovery_ID
    AND e.Client_Field_Name = 'UNIT';
    CURSOR Bill_totals IS
    Select mv_billdetail_case_sum.sum_paid as TOTAL_MEDICAL
    From mv_billdetail_case_sum
    where mv_billdetail_case_sum.event_id = V_Event_ID;
    CURSOR NonCash_Fee IS
    Select NVL(Sum(Recovery.Amount), 0) as Total_NonCash_Fee
    From Settlement, Recovery
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.
    Recovery_Transaction_Internal in ('05', '50', '52', '51');
    /* SWL 04/01/04 52653 */
    CURSOR Recovery_Totals IS
    Select round(avg(NVL(Recovery_Detail.Fees_Percent, 0) +
    NVL(Recovery_Detail.Admin_Percent, 0)),
    2) as Total_Fee_Percent,
    round(avg(NVL(Recovery_Detail.Fees_Percent, 0)), 2) as Subrogation_Fee_Percent,
    max(NVL(Recovery.Amount, 0)) as Recovery_Amount,
    Sum(NVL(Recovery_detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_Fee,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_Tax,
    Sum(NVL(Recovery_Detail.Admin_Taxes, 0)) as Administrative_tax,
    Sum(NVL(Recovery_Detail.Admin, 0)) as Total_Admin_Fee
    From Settlement, Recovery, Recovery_Detail
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    Group by Recovery_Detail.recovery_id;
    CURSOR Recovery_Totals_Positive IS
    /* Select Sum(Recovery.Amount) as Total_NonCash_Positive,
    Sum(NVL(Recovery_Detail.Fees_Taxes,0)+ NVL(Recovery_Detail.Admin_Taxes,0)) as Total_NonCash_Tax_Positive
    */ /* SWL 04/01/04 52653 */
    Select max(Recovery.Amount) as Total_NonCash_Positive,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Positive
    From Settlement, Recovery, Recovery_detail
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Amount >= 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in ('04', '17', '15') /*SWL 10/05/04 #63919*/--*009* added 15
    Group by Recovery_Detail.recovery_id;
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    CURSOR Recovery_NonFEE_Positive IS
    Select Sum(NVL(Recovery_Detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_NonCash_Fee_Positive
    From Settlement, Recovery, Recovery_detail
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Amount >= 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in
    ('05', '50', '52', '51')
    Group by Recovery_Detail.recovery_id;
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    CURSOR Recovery_Totals_Negative IS
    /* Select Sum(Recovery.Amount) as Total_NonCash_Negative,*/ /* SWL 04/01/04 52653 */
    Select max(Recovery.Amount) as Total_NonCash_Negative,
    Sum(NVL(Recovery_Detail.Fees_Taxes, 0) +
    NVL(Recovery_Detail.Admin_Taxes, 0)) as Total_NonCash_Tax_Negative
    From Settlement, Recovery, Recovery_Detail
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Amount < 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in ('04', '17', '15') /*SWL 10/05/04 #63919*/--*009* added 15
    Group by Recovery_Detail.recovery_id;
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    CURSOR Recovery_NonFEE_Negative IS
    Select Sum(NVL(Recovery_Detail.Fees, 0) + NVL(Recovery_Detail.Admin, 0)) as Total_NonCash_Fee_Negative
    From Settlement, Recovery, Recovery_Detail
    Where Recovery.Recovery_ID = V_Recovery_ID
    And Settlement.Settlement_id = Recovery.Settlement_id
    And Recovery.Amount < 0
    And Recovery.Recovery_id = Recovery_detail.Recovery_id(+)
    And Recovery.Recovery_Transaction_Internal in
    ('05', '50', '52', '51')
    Group by Recovery_Detail.recovery_id;
    -- Group by Recovery_Detail.Fees_Percent; /* SWL 04/01/04 52653 */
    --This is a generic cursor which will be used to control the number of rows inserted into the recovery_activity table
    --There has to be 1 row inserted into the recovery_activity table for each detail record in the recovery_detail table.
    --However, if no recovery_detail record exists there will be only 1 insert into the recovery_activity table.
    CURSOR Control_Detail_Loop
    IS
    Select 1
    FROM Recovery,
    Recovery_Detail
    Where Recovery.Recovery_ID = Recovery_Detail.Recovery_ID(+)
    And Recovery.Recovery_ID = V_Recovery_ID;
    /* SWL 04/01/04 Commented since the only time there were more entries in rd for a recovery is when there is a split fees */
    /* accounting does not want this to be displayed in detail. They need this aggregated as a single fee entry so the recovery */
    /* activity table will now have a single entry corresponding to each recovery in the recovery table. (#52653) */
    CURSOR Control_Detail_Loop IS
    Select 1 FROM Recovery where Recovery.Recovery_ID = V_Recovery_ID;
    /* DJ 10/25/04 # 64633 start*/
    CURSOR Event_Client_Market IS
    Select e.Client_Field_Data as Market
    From Event_Client_Field e, recovery r
    Where r.Event_ID = e.Event_ID
    AND r.Recovery_ID = V_Recovery_ID
    AND e.Client_Field_Name = 'MARKET';
    /* DJ 10/25/04 # 64633 end*/
    v_cur_day integer := 0;
    -----dj
    v_vendor_fee_wh number;
    v_total_vendor_fee_wh number;
    v_rec_itc recovery_activity.recovery_transaction_internal%type;
    --v_settlement_id settlement.settlement_id%type;
    --*004* start
    function unbundled_fee(pevent_id event.event_id%type,
    plowdate date,
    phighdate date) return number is
    -- function variables
    v_fee number(18, 2) := 0;
    v_month_revenue unbundled_recoveries.monthly_revenue%type := 0;
    v_cum_revenue unbundled_recoveries.cum_revenue%type := 0;
    v_contract_fee_per unbundled_recoveries.contractual_fee_per%type := 0;
    v_prev_cum_revenue unbundled_recoveries.cum_revenue%type := 0;
    v_cum_ub_rec unbundled_recoveries.cum_ub_recoveries%type := 0;
    v_cum_inv_paid unbundled_recoveries.cum_inv_paid%type := 0;
    v_month_rec unbundled_recoveries.monthly_recoveries%type := 0;
    v_cum_rec unbundled_recoveries.cum_recoveries%type := 0;
    v_event_id event.event_id%type;
    begin
    --v_month_rec and v_cum_inv_paid
    begin
    select event_id,
    (select sum(r.amount)
    from recovery r
    where r.event_id = e.event_id
    and trunc(r.recovery_date) between plowdate and phighdate) as monthly_recoveries,
    -- *006* added cum_rec
    (select nvl(sum(r.amount), 0)
    from recovery r
    where r.event_id = e.event_id
    and trunc(r.recovery_date) <= trunc(phighdate)) as cum_recoveries,
    (select sum(decode(nvl(ex.client_invoice_closed, 'N'),
    'N',
    ex.paid_amount,
    ex.client_invoice_received))
    from expense ex
    where ex.event_id = e.event_id
    and upper(ex.status) = 'PAID'
    and trunc(ex.check_date) <= phighdate
    and trim(ex.orig_client_invoice_date) is not null
    and nvl(ex.client_invoice_dispute, 'Y') = 'N') as cum_invoiced_paid
    into v_event_id, v_month_rec, v_cum_rec, v_cum_inv_paid
    from event e
    where e.event_id = pevent_id;
    exception
    when no_data_found then
    v_event_id := 0;
    v_month_rec := 0;
    v_cum_rec := 0;
    v_cum_inv_paid := 0;
    when others then
    v_event_id := 0;
    v_month_rec := 0;
    v_cum_rec := 0;
    v_cum_inv_paid := 0;
    end;
    -- *007* start
    -- if event previously written to table, get values from table
    begin
    select nvl(ub.cum_revenue, 0)
    into v_prev_cum_revenue
    from unbundled_recoveries ub
    where ub.event_id = pevent_id
    and ub.month_id =
    (select max(a.month_id)
    from unbundled_recoveries a
    where a.event_id = pevent_id
    and a.month_id < to_char(v_lowdate, 'YYYYMM'));
    exception
    when no_data_found then
    v_prev_cum_revenue := 0;
    when others then
    v_prev_cum_revenue := 0;
    end;
    -- *007* end
    --v_contract_fee_per
    begin
    select nvl(max(rd.fees_percent), 0)
    into v_contract_fee_per
    from recovery_detail rd
    where rd.recovery_id in
    (select r.recovery_id
    from recovery r,
    (select a.event_id, max(amount) as amount
    from recovery a
    where a.event_id = pevent_id
    and trunc(a.recovery_date) between plowdate and
    phighdate
    group by a.event_id) max_r
    where r.event_id = max_r.event_id
    and trunc(r.recovery_date) between plowdate and phighdate
    and r.amount = max_r.amount);
    exception
    when no_data_found then
    v_contract_fee_per := 0;
    when others then
    v_contract_fee_per := 0;
    end;
    v_cum_ub_rec := nvl(v_cum_rec, 0) - nvl(v_cum_inv_paid, 0);
    if ((nvl(v_cum_ub_rec, 0) > 0) and (nvl(v_month_rec, 0) <> 0)) then
    -- latest cumulative unbundled recoveries > 0
    v_cum_revenue := round(((v_contract_fee_per / 100) * v_cum_ub_rec),
    2);
    v_month_revenue := v_cum_revenue - v_prev_cum_revenue;
    end if;
    v_fee := v_month_revenue;
    return v_fee;
    exception
    when others then
    raise_application_error(-20106,
    substr('populate_recovery_activity.undebundled_fee: ' ||
    Sqlcode || Sqlerrm,
    1,
    500));
    return v_fee;
    end;

Maybe you are looking for

  • NFE Boas discussões - Leia antes de postar

    EM DESENVOLVIMENTO - SUGESTÕES DE ADIÇÃO E REMOÇÃO SÃO BEM VINDAS *** Bom dia Pessoal, Segue abaixo uma compilação de threads de NF-e. Observação: Estas threads estão respondidas, caso tenha algo "parecido" SEMPRE crie uma nova thread, pode até refer

  • SAP R/3 RFC Call to XI

    Hallo, My scenario is as follows: when sending a RFC to XI via the RFC adapter, I get a short dump with the following error: "the error occurred in an RFC call to another system (XI).The termination occurred in the function "RfcExtendedReceive" of th

  • Using 'Greater than/less than' in dynamic where condition

    Hi Guys, I am trying to use a logical expression with GT/LT condition in dynamic where, butits giving dump  "expression worngly parenthesised' . My query runs perfectly fine when the logical expression does not have 'GT/LT' . Is there a different way

  • Wrong face being shown in smart album

    This is using iphoto on mac Why does wrong face get selected in smart album.  My smart album is set to show faces that contain  "Griffiths"  but I don't want one person with same sir name to show.  I re name this persons face to  "Griffo" expecting h

  • What Rendering intent is used when exporting with a different color space?

    Hi, I would be ever so grateful if any one can tell me what rendering intent is used by LR4 when exporting using a custom colour space as there is not an option as there is with the print module. Thanks. Message title was edited by: Brett N