Need modify Running total query

CREATE TABLE DET
(DDT DATE,
DNO NUMBER,
DCODE VARCHAR2(6),
DAMOUNT NUMBER,
DINST NUMBER);
INSERT INTO DET VALUES (TO_DATE('01012010','DD/MM/YYYY'),7,1946,19674.5,NULL);
INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),8,1574,4800,NULL);
INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),8,1574,50000,208.333);
INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),9,1835,31600,208.333);
INSERT INTO DET VALUES (TO_DATE('08012010','DD/MM/YYYY'),6,1924,50000,232.558);
INSERT INTO DET VALUES (TO_DATE('02022010','DD/MM/YYYY'),9,1835,5000,NULL);
INSERT INTO DET VALUES (TO_DATE('02022010','DD/MM/YYYY'),9,1835,31600,131.667);
INSERT INTO DET VALUES (TO_DATE('05022010','DD/MM/YYYY'),8,1574,50000,208.333);
INSERT INTO DET VALUES (TO_DATE('10022010','DD/MM/YYYY'),6,1924,50000,232.558);
INSERT INTO DET VALUES (TO_DATE('01032010','DD/MM/YYYY'),8,1574,50000,208.333);
INSERT INTO DET VALUES (TO_DATE('01032010','DD/MM/YYYY'),6,1924,50000,232.558);
i have this query ;
SCOTT@orcl>select ddt,
  2  dno,
  3  dcode,
  4  newdamount damount,
  5  dinst,
  6  newdamount-nvl(dinst,0) run_tot
  7  from(
  8  select ddt,
  9  dno,
10  dcode,
11  damount,
12  dinst,
13  decode(nvl(to_number(to_char(ddt,'MM'))-1,0),0,damount,
14  damount-nvl(dinst,0)*(to_number(to_char(ddt,'MM'))-1)) newdamount
15  from det
16  order by ddt)
17  where dcode = '1835'
18  order by ddt,dno,damount,dinst nulls first;
it returns this result;
DDT               DNO DCODE     DAMOUNT      DINST    RUN_TOT
08/01/2010          9 1835        31600    208.333  31391.667
02/02/2010          9 1835         5000                  5000
02/02/2010          9 1835    31468.333    131.667  31336.666
The results last row should appear like this;
02/02/2010          9 1835    31391.667    131.667  31260 DAMOUNT for the row 02/02/2010 (where DINST > 0 ) should be 31391.667,(closing RUN_TOT of january)
and NOT 31468.333.
The above query logic could be enitrely wrong, because the criteria laid assuming that the instalment remains same every month.
Please someone who is well-verse with Lag or Sum ..Over analytic function, correct my code.
TY.

user613563 wrote:
Your query entirely missed one row with DAMOUNT 5000.
i expect the result to be;
DDT               DNO DCODE     DAMOUNT      DINST    RUN_TOT
08/01/2010          9 1835        31600    208.333  31391.667
02/02/2010          9 1835         5000                  5000
02/02/2010          9 1835    31391.667    131.667  31260
Well, i for one am not following the logic here, but this will give you the results you've posted (why doesn't the row with damount = 5000 factor in to the 'running total' in any way shape or form?)
select
  ddt, dno, dcode, damount, dinst, resolved
from
  select
    ddt, dno, dcode, damount, dinst,
    case when lag(trunc(ddt, 'MM')) over (order by ddt asc) != trunc(ddt, 'MM')
    then
      lag(damount-dinst) over (order by ddt asc) - dinst
    else
      damount-dinst
    end as resolved
  from det
  where dcode = '1835'
  and dinst is not null
    union all
  select
    ddt, dno, dcode, damount, dinst,
    damount as resolved
  from det
  where dcode = '1835'
  and dinst is null
  order by ddt asc, dinst nulls first
)Edited by: Tubby on Jan 11, 2010 2:47 PM
fixed the not equals sign since the forum eats less than / greater than symbols

Similar Messages

  • Needed a running total in query

    Dear Gurus...Can I've a running total in query like this:
    Item_ Open_Qty_ Rec_Qty_ Iss_Qty_ Bal_
    A 10 5 2 13
    A 0 4 5 12
    A 0 0 6 6
    In this query column Bal is required whose value should be calculated as:
    Bal = ((Open_Qty + Rec_Qty) - Iss_Qty)
    Thanx in advance.

    389 posts and still you seem unaware of:
    - how important it is to mention your database version.
    - the tag, which implicates that you haven't read the FAQ for a while.
    - the 'search' option you have on the right side of the screen.
    You can query running totals easily by using analytic function SUM.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Running Total Query need help

    Hi all,
    i have solution i got earlier form this forum.
    CREATE TABLE LHEADER
    (HDT DATE,
    HSR NUMBER,
    HCODE VARCHAR2(6),
    HAMOUNT NUMBER);
    INSERT INTO LHEADER VALUES (TO_DATE('01012009','DD/MM/YYYY'),1,101,5000);
    INSERT INTO LHEADER VALUES (TO_DATE('01022009','DD/MM/YYYY'),2,102,3000);
    INSERT INTO LHEADER VALUES (TO_DATE('01012009','DD/MM/YYYY'),3,103,6000);
    CREATE TABLE DDETAIL
    (DDT DATE,
    DHSR NUMBER,
    DHCODE VARCHAR2(6),
    DAMOUNT NUMBER,
    D1 NUMBER,
    D2 NUMBER,
    D3 NUMBER);
    INSERT INTO DDETAIL VALUES (TO_DATE('31012009','DD/MM/YYYY'),1,101,1500,NULL,NULL,10);
    INSERT INTO DDETAIL VALUES (TO_DATE('31012009','DD/MM/YYYY'),1,101,NULL,20,15,20);
    INSERT INTO DDETAIL VALUES (TO_DATE('28022009','DD/MM/YYYY'),1,101,NULL,20,12,20);
    INSERT INTO DDETAIL VALUES (TO_DATE('31032009','DD/MM/YYYY'),1,101,NULL,20,16,20);
    INSERT INTO DDETAIL VALUES (TO_DATE('30042009','DD/MM/YYYY'),1,101,NULL,20,20,20);
    INSERT INTO DDETAIL VALUES (TO_DATE('28022009','DD/MM/YYYY'),2,102,2000,15,NULL,15);
    INSERT INTO DDETAIL VALUES (TO_DATE('28022009','DD/MM/YYYY'),2,102,NULL,12,10,15);
    INSERT INTO DDETAIL VALUES (TO_DATE('31032009','DD/MM/YYYY'),2,102,NULL,12,15,8);
    INSERT INTO DDETAIL VALUES (TO_DATE('30042009','DD/MM/YYYY'),2,102,NULL,12,12,15);
    INSERT INTO DDETAIL VALUES (TO_DATE('31012009','DD/MM/YYYY'),3,103,NULL,30,20,25);
    INSERT INTO DDETAIL VALUES (TO_DATE('28022009','DD/MM/YYYY'),3,103,NULL,30,20,25);
    INSERT INTO DDETAIL VALUES (TO_DATE('31032009','DD/MM/YYYY'),3,103,NULL,30,20,25);
    INSERT INTO DDETAIL VALUES (TO_DATE('30042009','DD/MM/YYYY'),3,103,3000,NULL,30,25);
    INSERT INTO DDETAIL VALUES (TO_DATE('30042009','DD/MM/YYYY'),3,103,NULL,30,20,25);
    SELECT       ddt
    ,       dhsr
    ,       dhcode
    ,       NVL ( CASE
                   WHEN  d1 + d2 + d3  IS NULL
                   THEN  LAG (run_tot) OVER ( PARTITION BY  dhcode
                                                 ,                dhsr
                                                           ORDER BY       ddt
              END
               , amount
               )          AS amount
    ,       d1
    ,       d2
    ,       d3
    ,       run_tot
    FROM       (
         SELECT     d.ddt
         ,     d.dhsr
         ,     d.dhcode
         ,     NVL ( d.damount
                          , h.hamount
                      )               AS amount
         ,     d.d1
         ,     d.d2
         ,     d.d3
         ,     h.hamount - CASE
                           WHEN  d1 + d2 + d3     IS NULL
                        THEN  NULL
                        ELSE  SUM ( d.d1
                                         + d.d2
                                   + d.d3
                                   ) OVER ( PARTITION BY  d.dhcode
                                         ,                d.dhsr
                                                 ORDER BY      d.ddt
                          END          AS run_tot
         FROM     ddetail         d
         ,     lheader         h     where     d.dhcode     = h.hcode
                            AND     d.dhsr          = h.hsr
    ORDER BY  ddt
    ,            dhcode
    ,       d1 + d2 + d3     NULLS FIRST
    DDT                 DHSR DHCODE        AMOUNT            D1            D2            D3       RUN_TOT
    31/01/2009         1.000 101         1500.000                                    10.000
    31/01/2009         1.000 101         5000.000        20.000        15.000        20.000      4945.000
    31/01/2009         3.000 103         6000.000        30.000        20.000        25.000      5925.000
    28/02/2009         1.000 101         5000.000        20.000        12.000        20.000      4893.000
    28/02/2009         2.000 102         2000.000        15.000                      15.000
    28/02/2009         2.000 102         3000.000        12.000        10.000        15.000      2963.000
    28/02/2009         3.000 103         6000.000        30.000        20.000        25.000      5850.000
    31/03/2009         1.000 101         5000.000        20.000        16.000        20.000      4837.000
    31/03/2009         2.000 102         3000.000        12.000        15.000         8.000      2928.000
    31/03/2009         3.000 103         6000.000        30.000        20.000        25.000      5775.000
    30/04/2009         1.000 101         5000.000        20.000        20.000        20.000      4777.000
    30/04/2009         2.000 102         3000.000        12.000        12.000        15.000      2889.000
    30/04/2009         3.000 103         5775.000                      30.000        25.000
    30/04/2009         3.000 103         6000.000        30.000        20.000        25.000      5700.000
    14 rows selected.i want to the output to be like this now;
    the query should SUM d1,d2 & d3 where RUN_TOT is NULL.
    Rows with Null RUN_TOT should not be shown.
    DDT                 DHSR DHCODE        AMOUNT            D1            D2            D3       RUN_TOT
    31/01/2009         1.000 101         5000.000        20.000        15.000      *30.000*      4945.000
    31/01/2009         3.000 103         6000.000        30.000        20.000        25.000      5925.000
    28/02/2009         1.000 101         5000.000        20.000        12.000        20.000      4893.000
    28/02/2009         2.000 102         3000.000      *27.000*        10.000        *30.000*      2963.000
    28/02/2009         3.000 103         6000.000        30.000        20.000        25.000      5850.000
    31/03/2009         1.000 101         5000.000        20.000        16.000        20.000      4837.000
    31/03/2009         2.000 102         3000.000        12.000        15.000         8.000      2928.000
    31/03/2009         3.000 103         6000.000        30.000        20.000        25.000      5775.000
    30/04/2009         1.000 101         5000.000        20.000        20.000        20.000      4777.000
    30/04/2009         2.000 102         3000.000        12.000        12.000        15.000      2889.000
    30/04/2009         3.000 103         6000.000        30.000        *50.000      50.000*      5700.000
    14 rows selected.

    Hello Mr. Frank..
    I designed a report based on your solution, but when executed with the actual data, with what the user have entered,
    the report didn't returned the expected result. Yes, your logic with the earlier data provided by me was correct.
    but now the data has appeared in different manner.
    i tried to modify your query but didn't exactly succeed.
    for this data;
    CREATE TABLE LHEADER
    (HDT DATE,
    HSR NUMBER,
    HCODE VARCHAR2(6),
    HAMOUNT NUMBER);
    INSERT INTO LHEADER VALUES (TO_DATE('10/03/2010','DD/MM/YYYY'),12,1392,48571.1);
    INSERT INTO LHEADER VALUES (TO_DATE('16/03/2010','DD/MM/YYYY'),14,1526,40732);
    INSERT INTO LHEADER VALUES (TO_DATE('08/01/2010','DD/MM/YYYY'),9,1835,31600);
    CREATE TABLE DDETAIL
    (DDT DATE,
    DHSR NUMBER,
    DHCODE VARCHAR2(6),
    DAMOUNT NUMBER,
    D1 NUMBER,
    D2 NUMBER,
    D3 NUMBER);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/10/2009','DD/MM/YYYY'),12,1392,37103,NULL,12.986,217.434);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/11/2009','DD/MM/YYYY'),12,1392,37103,NULL,12.986,210.420);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/09/2009','DD/MM/YYYY'),12,1392,37103,NULL,12.986,210.420);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/12/2009','DD/MM/YYYY'),12,1392,2470,NULL,0,2.335);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/12/2009','DD/MM/YYYY'),12,1392,39573,NULL,13.851,231.909);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/01/2010','DD/MM/YYYY'),12,1392,39573,NULL,13.851,231.909);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/02/2010','DD/MM/YYYY'),12,1392,39573,NULL,13.850,209.466);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/02/2010','DD/MM/YYYY'),12,1392,4489.7,NULL,5.836,23.765);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/03/2010','DD/MM/YYYY'),12,1392,4489.7,NULL,2.918,26.311);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/03/2010','DD/MM/YYYY'),12,1392,39573,0,13.855,231.909);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/12/2008','DD/MM/YYYY'),14,1526,11620,NULL,0,50.046);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/01/2009','DD/MM/YYYY'),14,1526,11620,NULL,4.066,64.642);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/02/2009','DD/MM/YYYY'),14,1526,11620,NULL,4.066,58.387);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/03/2009','DD/MM/YYYY'),14,1526,11620,NULL,4.066,64.642);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/04/2009','DD/MM/YYYY'),14,1526,19220,NULL,6.726,103.472);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/05/2009','DD/MM/YYYY'),14,1526,19220,NULL,6.726,106.921);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/05/2009','DD/MM/YYYY'),14,1526,7600,NULL,NULL,17.73);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/06/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.386,144.387);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/07/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.386,149.200);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/08/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.387,48.129);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/08/2009','DD/MM/YYYY'),14,1526,26820,NULL,NULL,106.472);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/09/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.387,152.102);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/10/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.387,157.173);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/11/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.387,152.102);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/12/2009','DD/MM/YYYY'),14,1526,26820,NULL,9.387,157.173);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/01/2010','DD/MM/YYYY'),14,1526,5700,NULL,NULL,8.620);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/01/2010','DD/MM/YYYY'),14,1526,32520,NULL,11.382,190.576);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/02/2010','DD/MM/YYYY'),14,1526,32520,NULL,11.382,172.133);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/03/2010','DD/MM/YYYY'),14,1526,37745,NULL,13.21,221.196);
    INSERT INTO DDETAIL VALUES (TO_DATE('01/03/2010','DD/MM/YYYY'),14,1526,5225,NULL,NULL,4.939);
    INSERT INTO DDETAIL VALUES (TO_DATE('04/01/2010','DD/MM/YYYY'),9,1835,31600,131.667,11.06,185.185);
    INSERT INTO DDETAIL VALUES (TO_DATE('05/02/2010','DD/MM/YYYY'),9,1835,31468.333,131.667,11.014,166.567);
    INSERT INTO DDETAIL VALUES (TO_DATE('08/03/2010','DD/MM/YYYY'),9,1835,31336.666,131.667,10.968,183.641);
    INSERT INTO DDETAIL VALUES (TO_DATE('10/04/2010','DD/MM/YYYY'),9,1835,31204.999,131.667,10.922,176.971);
    i modified your query like this;
    SELECT   ddt
    ,   dhsr
    ,   dhcode
    ,   amount
    ,   d1
    ,   d2
    ,   d3
    ,   run_tot
    FROM   (
      SELECT   ddt
      ,   dhsr
      ,   dhcode
      ,   NVL ( CASE
         WHEN  NVL(d1 + d2 + d3,0) = 0
         THEN  LAG (run_tot) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
                                     ORDER BY   ddt
        END
             , amount
             )  AS amount
      ,   SUM (NVL(d1,0)) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
           ,  a_cnt
         ) AS d1
      ,   SUM (NVL(d2,0)) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
           ,  a_cnt
         ) AS d2
      ,   SUM (NVL(d3,0)) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
           ,  a_cnt
         ) AS d3
      ,   run_tot
      FROM   (
        SELECT d.ddt
        , d.dhsr
        , d.dhcode
        , NVL ( d.damount
                     , h.hamount
                 )    AS amount
        , d.d1
        , d.d2
        , d.d3
        , h.hamount - CASE
                  WHEN  NVL(d1 + d2 + d3,0) = 0
           THEN  NULL
           ELSE  SUM ( NVL(d.d1
                        + d.d2
                + d.d3,0)
                  ) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
                            ORDER BY      d.ddt
                     END   AS run_tot
        , COUNT (d1 + d2 + d3) OVER ( PARTITION BY  dhcode,to_char(ddt,'yyyymm')
                ORDER BY      d.ddt  DESC
              ) AS a_cnt
        FROM ddetail     d
        , lheader     h where d.dhcode = h.hcode
               AND d.dhsr  = h.hsr
    --WHERE   run_tot IS NOT NULL
    WHERE       to_char(ddt,'yyyymm') = '201003'
    ORDER BY  ddt
    ,        dhcode
    ,   d1 + d2 + d3
    i got this output;
    DDT              DHSR DHCODE     AMOUNT         D1         D2         D3    RUN_TOT
    01/03/2010         12 1392       4489.7          0     16.773     258.22
    01/03/2010         12 1392        39573          0     16.773     258.22  48325.336
    01/03/2010         14 1526        37745          0      13.21    226.135
    01/03/2010         14 1526         5225          0      13.21    226.135
    08/03/2010          9 1835    31336.666    131.667     10.968    183.641  31273.724
    but the expected result should be like this;
    DDT              DHSR DHCODE     AMOUNT         D1         D2         D3    RUN_TOT
    01/03/2010         12 1392              39573          0     16.773    258.220  39573.000
    01/03/2010         14 1526              37745                13.210    226.135  37745.000
    08/03/2010          9 1835          31336.666    131.667     10.968    183.641  31204.999
    and when i change the last condition part...to
    WHERE   run_tot IS NOT NULL
    AND       to_char(ddt,'yyyymm') = '201003'
    ORDER BY  ddt
    ,        dhcode
    ,   d1 + d2 + d3          ...
    DDT              DHSR DHCODE     AMOUNT         D1         D2         D3    RUN_TOT
    01/03/2010         12 1392        39573          0     16.773     258.22  48325.336
    08/03/2010          9 1835    31336.666    131.667     10.968    183.641  31273.724
       1. The row for dhcode 1526 does not appear and
       2. The runtot for 1835 gets wrongly calculated (it should be 31336.666-131.667=31204.999)Please suggest .
    TYVM.

  • Permissions needed to run tarantella query audit?

    Hi
    I'm trying to run the "tarantella query audit ..." command to check for log file entries, using the account I use for all sgd admin.
    I've never done this before, and I get the error "you do not have permission to run this script" - can't find anything in the admin guide relating to specific permissions for this option, what am I missing?
    Thanks
    mrtng

    I did a quick test in my environment and found the runbook worked fine when run normally, but threw an access denied error when using runbook tester (my account is admin also). Just reinforcing to me that runbook tester is not a very useful tool.
    To troubleshoot, I'd try a couple changes:
    Create a new runbook with only the Run Program activity in it, and hard code the robocopy command that worked in the command line in the Command field
    Shouldn't need to specify server name if running locally on runbook server
    Leave everything else in the activity at defaults (no run as account in Advanced, and use service account in Security)
    Make sure activity-specific published data logging is enabled for the runbook
    Temporarily
    enable trace logging for Orchestrator remoting service, policymodule, and runbook service
    Then check in and run, and see if it works or there is more info in the trace logs.
    Has this server been "hardened" with any nonstandard policies or configuration? If so would want to peel those off to eliminate some kind of lockdown as the issue.
    Runbook:
    Noah Stahl | Automys |
    Downloadable Microsoft automation examples and solutions

  • MDX query - need to run different query (where clause) on mondays

    The below query works OK and uses the substitution variable CurrentWeek in the WHERE clause, but I have one shortcoming that I need your help for:
    The query works fine for all days but mondays. On Mondays I need the query to fetch numbers from last week (as opposed to current week) as the query returns null as the cubes have no data for current week on mondays. Hence I need to change the where clause to use substitution variable LastWeek, or in some other way run a different query on mondays. I have another substitution variable called WeekDay which I can use to test which day of the week it is, but I am not sure of the syntax I need to use to test for day of week and then have the query use different substitution variables as a result of this test.
    Please help.
    Henning Strand
    SELECT NON EMPTY {[Measures].[meas_sg]} ON COLUMNS,
    NON EMPTY {[Kunde],[Kunde].[KU01],[Kunde].[KU02],[Kunde].[KU03],[Kunde].[KU04]} ON ROWS
    FROM MIFS.MIFS
    WHERE ([Marked].[Dagligvare],[Tid].[&CurrentWeek])

    Or to go off of Sean's suggestion, programmatically change the value of the substitution variable, and leave the code alone.
    Other thoughts -- have a load process to a single cell (sorry, my BSO roots are showing, but the concept is the same, load a single number) and then do a boolean test off its value -- 0 = Monday, 1 = the rest of the week.
    Regards,
    Cameron Lackpour

  • MS SQL database needs to run mdx query to analysis services to retrieve data from a BPC 10 Netweaver cube(view only)

    We are in the process of migrating from BPC7 SP12 Microsoft sql server to BPC10 netweaver on a sql server with BW7.4 and need to integrate our home grown data warehouse which is on a Microsoft sql server.  The data warehouse currently connects to BPC7 using integration services/analysis services and runs mdx queries to analysis services to retrieve data from the BPC7 cube (view only).  Please provide documentation on how to create this same integration with our data warehouse using BPC10 netweaver on a sql server.

    When you were setting up your ODBC data source for
    the Text driver, did you click on the "Options"
    button? There's a lot of options in there that I
    didn't understand at first glance.Yes I clicked on the options button, but the only thing there is dealing with file extensions. I left it set to the default.
    I have since tried closing my connection after I insert a record, I then try executeQuery, but still no luck. Seems strange that I can write to the file but not read from it. If any thing I'd expect the opposite problem.
    I have also tried using the class "JoltReport" from the sun tutorial instead of my own with the same result.
    Message was edited by:
    Hentay

  • Need Pay Run results Query in R12

    Hi Experts,
    Good morning to all.
    I have a requirement to display the fields like Payroll name,Payroll Period,element name and their values from pay run results.
    if anybody worked on this requirement please send me the select statement.
    Cheers
    Ram

    Does this help -
    select papf.employee_number,papf.full_name,ppa.effective_date,pp.payroll_name,
    pet.element_name,piv.name input_value,prrv.result_value
    from apps.pay_payroll_actions ppa, pay_assignment_actions paa,
    pay_payrolls_f pp,pay_run_results prr, pay_run_result_values prrv,
    pay_input_values_f piv,pay_element_types_f pet,
    apps.per_all_assignments_f paaf, apps.per_all_people_f papf
    where ppa.payroll_action_id = :payroll_action_id -- give your payroll_action_id
    and ppa.payroll_action_id = paa.payroll_action_id
    and ppa.payroll_id = pp.payroll_id
    and paa.assignment_action_id = prr.assignment_action_id
    and prr.run_result_id= prrv.run_result_id
    and prrv.input_value_id = piv.input_value_id
    and piv.element_type_id = pet.element_type_id
    and paaf.assignment_id = paa.assignment_id
    and paaf.person_id = papf.person_id
    and trunc(sysdate) between pp.effective_start_date and pp.effective_end_date
    and trunc(sysdate) between pet.effective_start_date and pet.effective_end_date
    and trunc(sysdate) between piv.effective_start_date and piv.effective_end_date
    and trunc(sysdate) between paaf.effective_start_date and paaf.effective_end_date
    and trunc(sysdate) between papf.effective_start_date and papf.effective_end_date
    order by employee_number;

  • Need to run a query to select # of counts based on each month

    Let's say I have a talble with 12 months, each month has some data.
    I want to run a select count(*) to get result of how many rows per month, like Jan----100, Feb---90, etc.
    How do I do that?
    Thanks in advance.

    user569151 wrote:
    Let's say I have a talble with 12 months, each month has some data.
    I want to run a select count(*) to get result of how many rows per month, like Jan----100, Feb---90, etc.
    How do I do that?
    Thanks in advance.May be like this:
    SELECT EXTRACT(MONTH FROM date_column),COUNT(*)
    FROM TABLE_NAME
    GROUP BY EXTRACT(MONTH FROM date_column);

  • How to do running totals in a query

    Hi Guys, I have following data sample and desired output and I need a running total or subtotals on each row for two quntity fields on same row.
    Current data:
    ID - ---Day----- Qty1 Qty2
    Abc 04/01/2009 100 50
    abc 04/02/2009 70 20
    def 04/01/2009 10 30...
    Desired outPut:
    ID - ---Day----- Qty1 Subtoal Qty1 Qty2 SubtotalQty2
    Abc 04/01/2009 100 100 50 50
    abc 04/02/2009 70 170 20 70
    def 04/01/2009 10 180 30 30

    Hi,
    There's one thing in your example, regarding the last line:
    def 04/01/2009 10 180 30 30I assumed you meant:
    def 04/01/2009 10 180 30 100 <<== running total should be 100Am I correct?
    Then try:
    SQL> with t as (
      2  select  'Abc' col1, to_date('04/01/2009', 'dd/mm/yyyy') col2, 100 col3, 50 col4 from dual union all
      3  select'abc', to_date('04/01/2009', 'dd/mm/yyyy'), 70, 20 from dual union all
      4  select 'def', to_date('04/01/2009', 'dd/mm/yyyy'), 10, 30 from dual
      5  ) --Actual query starts here:
      6  select col1
      7  ,      col2
      8  ,      col3
      9  ,      sum(col3) over (order by rownum) rt_col3
    10  ,      col4
    11  ,      sum(col4) over (order by rownum) rt_col4
    12  from t;
    COL COL2             COL3    RT_COL3       COL4    RT_COL4
    Abc 04-01-2009        100        100         50         50
    abc 04-01-2009         70        170         20         70
    def 04-01-2009         10        180         30        100Edited by: hoek on Jun 24, 2009 5:19 PM added question

  • Running total of outputs

    Hi i have a list of 11 numbers as a cfoutput, i need a
    running total but the problem i have is not all 11 numbers will be
    selected
    ie
    No 1 = 2000
    No 2 = 5000
    No 3 = 7000
    No 4 = 7000
    No 5 = left blank
    No 6 = 7000
    No 7 = 7000
    No 8 = left blank
    No 9 = 7000
    No 10 = 7000
    No 11 = 7000
    Total = needs to be No1+No2+No3 etc this needs to be an
    output as well
    the error i get is can not be converted this is because of
    the left blank numbers how would i do this
    Many thanks

    If the list of numbers is coming from a query, Q of Q should
    fix you right up.

  • Help with a resetting running total

    Hi, I need help with a query that will have a running total that resets at certain points
    Version
    BANNER                                                                        
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production    
    PL/SQL Release 11.2.0.3.0 - Production                                          
    CORE  11.2.0.3.0  Production                                                        
    TNS for Linux: Version 11.2.0.3.0 - Production                                  
    NLSRTL Version 11.2.0.3.0 - Production sample data
    create table t ( stat varchar2(3)
                   , beg_dt date
                   , end_dt date
                   , dur    number);
    Insert into t  values ('ACT',to_date('01-JUL-2012','DD-MON-YYYY'),to_date('31-JUL-2012','DD-MON-YYYY'),31);
    Insert into t  values ('ACT',to_date('01-AUG-2012','DD-MON-YYYY'),to_date('31-AUG-2012','DD-MON-YYYY'),31);
    Insert into t  values ('ACT',to_date('01-SEP-2012','DD-MON-YYYY'),to_date('30-SEP-2012','DD-MON-YYYY'),30);
    Insert into t  values ('LOA',to_date('01-OCT-2012','DD-MON-YYYY'),to_date('25-OCT-2012','DD-MON-YYYY'),25);
    Insert into t  values ('LOA',to_date('26-OCT-2012','DD-MON-YYYY'),to_date('31-OCT-2012','DD-MON-YYYY'),6);
    Insert into t  values ('LOA',to_date('01-NOV-2012','DD-MON-YYYY'),to_date('04-NOV-2012','DD-MON-YYYY'),4);
    Insert into t  values ('ACT',to_date('05-NOV-2012','DD-MON-YYYY'),to_date('10-NOV-2012','DD-MON-YYYY'),6);
    Insert into t  values ('LOA',to_date('11-NOV-2012','DD-MON-YYYY'),to_date('30-NOV-2012','DD-MON-YYYY'),20);
    Insert into t  values ('LOA',to_date('01-DEC-2012','DD-MON-YYYY'),to_date('15-DEC-2012','DD-MON-YYYY'),15);
    Insert into t  values ('ACT',to_date('16-DEC-2012','DD-MON-YYYY'),to_date('31-DEC-2012','DD-MON-YYYY'),16);
    Insert into t  values ('LOA',to_date('01-JAN-2013','DD-MON-YYYY'),to_date('31-JAN-2013','DD-MON-YYYY'),31);
    Insert into t  values ('LOA',to_date('01-FEB-2013','DD-MON-YYYY'),to_date('05-FEB-2013','DD-MON-YYYY'),5);
    Insert into t  values ('LOA',to_date('06-FEB-2013','DD-MON-YYYY'),to_date('15-FEB-2013','DD-MON-YYYY'),10);
    Insert into t  values ('LOA',to_date('16-FEB-2013','DD-MON-YYYY'),to_date('25-FEB-2013','DD-MON-YYYY'),10);
    Insert into t  values ('LOA',to_date('26-FEB-2013','DD-MON-YYYY'),to_date('28-FEB-2013','DD-MON-YYYY'),3);
    Insert into t  values ('LOA',to_date('01-MAR-2013','DD-MON-YYYY'),to_date('10-MAR-2013','DD-MON-YYYY'),10);
    Insert into t  values ('ACT',to_date('11-MAR-2013','DD-MON-YYYY'),to_date('31-MAR-2013','DD-MON-YYYY'),21);
    Insert into t  values ('ACT',to_date('01-APR-2013','DD-MON-YYYY'),to_date('30-APR-2013','DD-MON-YYYY'),30);
    Insert into t  values ('LOA',to_date('01-MAY-2013','DD-MON-YYYY'),to_date('25-MAY-2013','DD-MON-YYYY'),25);
    Insert into t  values ('LOA',to_date('26-MAY-2013','DD-MON-YYYY'),to_date('31-MAY-2013','DD-MON-YYYY'),6);
    Insert into t  values ('LOA',to_date('01-JUN-2013','DD-MON-YYYY'),to_date('04-JUN-2013','DD-MON-YYYY'),4);
    Insert into t  values ('ACT',to_date('05-JUN-2013','DD-MON-YYYY'),to_date('30-JUN-2013','DD-MON-YYYY'),26);This is close.
    select stat
        , beg_dt
        , end_dt                            
        , dur
        , sum( case stat when 'LOA' then dur else 0 end ) over ( partition by stat order by beg_dt) tot1
    from t
    order by beg_dt
    STAT BEG_DT      END_DT      DUR TOT1
    ACT  01-JUL-2012 31-JUL-2012  31    0
    ACT  01-AUG-2012 31-AUG-2012  31    0
    ACT  01-SEP-2012 30-SEP-2012  30    0
    LOA  01-OCT-2012 25-OCT-2012  25   25
    LOA  26-OCT-2012 31-OCT-2012   6   31
    LOA  01-NOV-2012 04-NOV-2012   4   35
    ACT  05-NOV-2012 10-NOV-2012   6    0
    LOA  11-NOV-2012 30-NOV-2012  20   55
    LOA  01-DEC-2012 15-DEC-2012  15   70
    ACT  16-DEC-2012 31-DEC-2012  16    0
    LOA  01-JAN-2013 31-JAN-2013  31  101
    LOA  01-FEB-2013 05-FEB-2013   5  106
    LOA  06-FEB-2013 15-FEB-2013  10  116
    LOA  16-FEB-2013 25-FEB-2013  10  126
    LOA  26-FEB-2013 28-FEB-2013   3  129
    LOA  01-MAR-2013 10-MAR-2013  10  139
    ACT  11-MAR-2013 31-MAR-2013  21    0
    ACT  01-APR-2013 30-APR-2013  30    0
    LOA  01-MAY-2013 25-MAY-2013  25  164
    LOA  26-MAY-2013 31-MAY-2013   6  170
    LOA  01-JUN-2013 04-JUN-2013   4  174
    ACT  05-JUN-2013 30-JUN-2013  26    0 I need a running total of LOA stat that will reset itself with each break of ACT so that I get :
    STAT BEG_DT      END_DT      DUR TOT1
    ACT  01-JUL-2012 31-JUL-2012  31    0
    ACT  01-AUG-2012 31-AUG-2012  31    0
    ACT  01-SEP-2012 30-SEP-2012  30    0
    LOA  01-OCT-2012 25-OCT-2012  25   25
    LOA  26-OCT-2012 31-OCT-2012   6   31
    LOA  01-NOV-2012 04-NOV-2012   4   35
    ACT  05-NOV-2012 10-NOV-2012   6    0
    LOA  11-NOV-2012 30-NOV-2012  20   20
    LOA  01-DEC-2012 15-DEC-2012  15   35
    ACT  16-DEC-2012 31-DEC-2012  16    0
    LOA  01-JAN-2013 31-JAN-2013  31   31
    LOA  01-FEB-2013 05-FEB-2013   5   36
    LOA  06-FEB-2013 15-FEB-2013  10   46
    LOA  16-FEB-2013 25-FEB-2013  10   56
    LOA  26-FEB-2013 28-FEB-2013   3   59
    LOA  01-MAR-2013 10-MAR-2013  10   69
    ACT  11-MAR-2013 31-MAR-2013  21    0
    ACT  01-APR-2013 30-APR-2013  30    0
    LOA  01-MAY-2013 25-MAY-2013  25   25
    LOA  26-MAY-2013 31-MAY-2013   6   31
    LOA  01-JUN-2013 04-JUN-2013   4   35
    ACT  05-JUN-2013 30-JUN-2013  26    0 Any help would be appreciated, thanks.

    Hi,
    So, you want a separate total whenever there's an 'ACT'. That's what PARTITION BY is for. You need to add the number of ACTs already encountered (which I called act_cnt) to the PARTITION BY clause that gets you the SUM.
    We can get act_cnt using the analytic functions like COUNT or SUM, but, since one analytic function can't depend on another computed inthe same query, we need to use a sub-query to compute act_cnt.
    Here's one way:
    WITH     got_act_cnt     AS
         SELECT     stat, beg_dt, end_dt, dur
         ,     COUNT (CASE WHEN stat = 'ACT' THEN 1 END)
                  OVER (ORDER BY  beg_dt)   AS act_cnt
         FROM    t
    SELECT       stat, beg_dt, end_dt, dur
    ,       SUM (CASE stat WHEN 'LOA' THEN dur ELSE 0 END)
             OVER ( PARTITION BY  stat
                     ,                act_cnt     -- ***** NEW *****
                 ORDER BY      beg_dt
               )       AS totl
    FROM      got_act_cnt
    ORDER BY  beg_dt
    ;Are 'ACT' and 'LOA' the only possible values for stat? If so, the query above can probably be simplified.

  • Can you run a Query in a Process Chain?

    As part of a data validation process chain, I need to run a query and send the results by email.  I've created the query (with the exception) and set it up in information broadcaster to be sent by email.  I thought that I would be able to just drop in the "Exception Reporting" process into the process chain and be able to select the query to run.  Needless to say, it don't work that way.
    If anyone has ran a query in a process chain, please let me know how you did it?
    Also if someone knows how the "Exception Reporting" process in RSPC works, please share?
    Thanks

    Patel, we may be able to rethink our approach and use the event data change that was mentioned in the document you sent.
    I was hoping to be able to do everything from within a process chain.  Does anyone know how to use the "Exception Reporting" process that is available in RSPC?  Is it a leftover from the 3.X days that can't really be used in 7.0?

  • How do you run a query to view duplicate records?

    I need to run a query with the query generator to produce a list of matching records. We have a problem whereby sales orders can come in by phone and email and therefore they sometimes get put on the system twice. I need to produce a query which picks up any orders where the CardCode and Document Value match, within say two days of each other.
    Please help?

    Hi Wendy Burt....
    Try This
    SELECT   COUNT(T0.[CardCode])as Duplicatecount, T0.[CardName], T0.[DocTotal] FROM ORDR T0
    WHERE T0.[DocTotal] IN ( select t1.doctotal from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    AND
    T0.CARDCODE IN ( select t1.CardCode from ORDR t1
    where t0.cardcode=t1.CardCode AND datediff(dd, t0.docdate,getdate())<=2)
    and t0.docstatus = 'O' and t0.doctotal >0
    GROUP BY  T0.[CardName], T0.[DocTotal]
    Regards,
    Kennedy

  • Row wise running total

    is there any method to create row wise running total in Crystal Reports?

    >
    gourav.sengupta wrote:
    > Hi,
    >
    > I needed a running total but for rows. Therefore if the data set is in the following manner:
    >
    > Column 1             Column 2             Column 3             Column 4
    > A                         12                       13                       14
    > B                         11                       10                       19
    >
    > The the running total will appear as:
    > RT                        23                       23                       33
    >
    >
    > Thanks and Regards,
    > Gourav
    I am confused as to what you want.
    Your sample shows sums for collumns, not rows. You do not need a running total for this, just sum them.
    If you want to total each row, make a formula that adds them up and place on the row.

  • CALCULATE RUNNING TOTALS FOR SUBSETS OF THE DATA IN A SECTION

    How can I calculate a running total in BO XI Release 2, (WebI), where my totals only include the value of the current row and the previous 5 rows?
    For Example:
            In the data, behind my BO table, I have transaction dates that roll up to a dimension called Period.  The "Period" represents the Year and Month of the transaction date, which is a month's worth of data at a time.  Each month contains an aggregated value that is the Population of items for that month.  The RunningSum function in BO works well, except that I need the running total to only include the current month along with the last 5 months, for a total of 6 months worth of data per row. 
            See my example below.  The Period of JAN 2009 includes the Population for JAN 2009 plus the sum of the Populations from AUG 2008 through DEC 2008 for a total of 6 months worth of data.  FEB 2009 includes SEP 2008 through FEB 2009.  MAR 2009 includes OCT 2008 through MAR 2009...
    __________Period_______Population_______6 MOS
    __________200801__________54___________54
    __________200802__________60__________114
    __________200803__________50__________164
    __________200804__________61__________225
    __________200805__________65__________290
    __________200806__________58__________348
    __________200807__________70__________364
    __________200808__________64__________368
    __________200809__________59__________377
    __________200810__________62__________378
    __________200811__________66__________379
    __________200812__________75__________396
    __________200901__________62__________388
    __________200902__________53__________377
    __________200903__________63__________381
    __________200904__________67__________386
    Six months is obviously no magic number.  I'd like the solution to be flexible enough to use for 3, 12, 18, or 24 month periods as well.

    Hi Frank,
    can you consider building the rolling sums directly in your database using subselects in the select statement:
    eg. select attr1, attr2,key2, (select sum(key1) from B where B.month<=A.month and B.month>=A.month-6) from A
    Just create a key figure in your universe and add the subselect statement select sum(key1) from B where B.month<=A.month and B.month>=A.month-6 as select-clause.
    ATTENTION: This is SQL pseudo code.
    Regards,
    Stratos

Maybe you are looking for