Query with running Total

Hello,
I have a insert from query:
     insert into tablexxxx
     SELECT ALL      G.c1, G.c2,
                     CASE
                     WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                     WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                     WHEN G.colt1      =   'A'             THEN &DATASI
                     END colt3,
                 CASE G.colt2 WHEN 'D' THEN  G.IMP1  else 0   END    IMPD,
                CASE G.colt2 WHEN 'A' THEN  G.IMP1  else 0   END    IMPA,
                     CASE
                     WHEN G.colt1  NOT IN ( 'B', 'C')
                     THEN (&VALU1 -1)
                     ELSE COLX
                     END      COLX,
     FROM table1 G, table2 S, table3 C
     WHERE  G.colt4    = S.colt4      
     AND (     (G.colt1  = 'M' AND  G.DATA1 BETWEEN &DATA_IP AND &DATA_FP AND G.TCOL6 = EXTRACT(YEAR FROM &DATA_IP) - 1 )
            OR (G.colt1 <> 'M' AND  G.DATA1 BETWEEN &DATA_IP AND &DATA_FP)
            OR (G.colt1  = 'A'  AND (&DATASI BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAIE) )
            OR (G.colt1  = 'B'  AND (&DATASF BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAFE) )
            OR (G.colt1  = 'C'  AND (&DATASF BETWEEN &DATA_IP AND &DATA_FP AND G.DATA1 = &DATAFE) )  )
     AND  G.colt5  = C.colt5(+)
     ORDER BY 3,4,5 ; 
     NOW I HAVE TO INSERT in previous query 2 RUNNING TOTALE e.g:
           sum(CASE G.colt2 WHEN 'D' THEN  G.IMP1 + &myvalue1  else 0   END    IMPD) over (order by CASE
                     WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                     WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                     WHEN G.colt1      =   'A'             THEN &DATASI
                     END) running_sum,
         sum(CASE G.colt2 WHEN 'A' THEN  G.IMP1 + &myvalue2  else 0   END    IMPA) over ((order by CASE
                     WHEN G.colt1  NOT IN ( 'A', 'B', 'C') THEN G.DATA1
                     WHEN G.colt1      IN ( 'B', 'C')      THEN &DATASF
                     WHEN G.colt1      =   'A'             THEN &DATASI
                     END) running_sum1    Could anyone help me to write it? ( maybe is better write it with SELECT-UNION?)
Thanks in advance

Hi IceMan,
I think about having resolved in this way, I don't sincerely believe that is the optimal solution,
but of sure it is that simpler,anyway, one opinion of yours would be very pleasant:
1) I have made an Insert-Select with the 2 runnings total = 0
INSERT INTO  TABLEX
SELECT ALL G.c1, G.D2,
CASE
  WHEN G.colt1 NOT IN ( 'A', 'B', 'C') THEN G.DATA1
  WHEN G.colt1 IN ( 'B', 'C') THEN &DATASF
  WHEN G.colt1 = 'A' THEN &DATASI
END D1,
CASE G.colt2 WHEN 'D' THEN G.IMP1 else 0 END IMPD,
CASE G.colt2 WHEN 'A' THEN G.IMP1 else 0 END IMPA,
CASE
WHEN G.colt1 NOT IN ( 'B', 'C')
THEN (&VALU1 -1)
ELSE COLX
END COLX, 0 RUNIMP_D, 0 RUNIMP_A
FROM table1 G, table2 S, table3 C
WHERE ........
ORDER BY 3,4,5 ;2) in the populated table(step 1) I have made an UPDATE-SELECT getting the 2 runnings total
UPDATE TABLEX A SET  (RUNIMP_D, RUNIMP_A ) =(
SELECT  --G.D1, G.D2, G.IMPD,G.IMPA,
         SUM(G.IMPD) OVER (ORDER BY G.D1, G.D2,G.IMPD) RS1  ,
       SUM(G.IMPA) OVER (ORDER BY  G.D1, G.D2,G.IMPA) RS2
  FROM TABLEX G
WHERE  G.ROWID = A.ROWID     
--ORDER BY 1,2
where G.D1 is that I get from
CASE
WHEN G.colt1 NOT IN ( 'A', 'B', 'C') THEN G.DATA1
WHEN G.colt1 IN ( 'B', 'C') THEN &DATASF
WHEN G.colt1 = 'A' THEN &DATASI
END D1
and
G.IMPD is:
CASE G.colt2 WHEN 'D' THEN G.IMP1 else 0 END IMPDThanks again for your reply

Similar Messages

  • How to create crystal report 2008 with running totals?

    i want to create a report with running totals as follows:
    Balance B/F 1000.00
    Invoices     Receipts    Running B/ce
    100                            1100
                     500             600
                     500             100
    300                              400
                     400                0
    The B/F field is passed as a Parameter.

    Hi  panayiotis,
    In order to create a running total you need to have absolute clarity on the following:
    (i)Whether the running total be set on change of field/record/group.
    (ii)Whether the running total be set on change of record/group OR never.
    Make the appropriate choice.
    Apply this to the field to summarize and type of summary in Running Total Pane.
    Thanks,
    Amogh.

  • Problems with running totals

    I'm having some trouble getting the correct number when a drive has multiple incentives associated with the drive.  And to explain as fully as I can, every drive has a projecture procedure count and when complete, a performed procedure count associated with the drive.  And when a drive has an incentive assigned to it, I would like to count the drive's projected and performed procedure count to the incentive count.  In the screen shot, there are five drives with four each having one incentive to the drive. The incentive count in which only one incentive is assigned to one drive is correct, but the Fandango pre-drive and post-drive counts are off because it is not counting the 12 and 15 that were collected on the bottom drive.
    For my running total, I am summing the ProceduresPerformed field, evaluating on the change of field of DriveID (each drive) and reseting on the change of field for EquipmentID (each incentive has its own unique ID).
    What would be the best way to handle drives with multiple incentives to get the correct count?

    Hello DJ,
    Let me see if I can explain more clearly to help you understand.
    I think the most important thing is that each drive is unique and will have one projected procedure number and one performed procedure number.  But each drive may have multiple incentives assigned to each drive. Where I run into trouble is when I have more than one incentive on a drive.
    I'll try to illustrate below:
    Drive
    Projected
    Performed
    Incentive(s):
    A
    10
    12
    Movie Tickets
    Gift Card
    B
    5
    10
    Movie Tickets
    Beach Towel
    C
    20
    25
    Gift Card
    Based on these entries, what I'm trying to have summarized should look like this:
    Pre-Drive (Sum of Projected)
    Post-Drive (Sum of Performed)
    Movie Tickets
    15
    22
    Gift Card
    30
    37
    Beach Towel
    5
    10
    So if an incentive is assigned to a drive, I would like to have all of the projected and performed numbers summarized that the particular incentive appears on.  Hopefully this makes sense.
    And one last screen shot here of a query I ran against the database to illustrate how a drive can have multiple incentives on the drive.

  • Problem with "Running Total"

    Hi, I've created a calcution using the analytic function template "Running Total" and the worksheet ran fine. I saved the workbook with this new calculation.
    The next day when I attempt to run that worksheet I received the error "Database Error - ORA-00923 From keyword not found where expected."
    For some reason it's loosing the SUM( ) from the calc.
    Here's what the calc looks like now -> No of Queries OVER(PARTITION BY Calendar Year and Month ORDER BY Calendar Date ASC ROWS UNBOUNDED PRECEDING )
    This is what it looks like when I created it -> SUM(No of Queries) OVER (PARTITION BY Calendar Year and Month ORDER BY Calendar Date ASC ROWS UNBOUNDED PRECEDING)
    Brent.

    Well, I guess my thought process was declaring warrBaseYrPrc in the @currWarrBaseYrPrc formula which would make it a global variable and accessible to all formulas where that same variable is declared. I thought that if I declared warrBaseYrPrc in @currWarr2YrPrc, it would have its value as calculated in @currWarrBaseYrPrc and use that. And since @currWarr2YrPrc returns the variable warrBaseYrPrc with some slight modifications depending on the if statment, it shouldn't have refused use in the Running Total.
    So I'm kind of leaning more toward an ordering screw up (i.e. it didn't know what formula to evaluate first because they were all in the same section and dependent on one another because of nesting formula invocations, and thus treated @currWarr2YrPrc warrBaseYrPrc variable, and subsequent calculations, as a constant as you talked about and you can't RT constants). I still find it perplexing why it would treat a variable as a constant, but I guess I'll have to experiment with it a little bit.
    By the way, do you know of any good free crystal report debugging tools?

  • Running Connected Query with Run Control Parameters using App Engine

    Hello,
    I created a connected query that has 1 parent query and 1 child query, and use this as DataSource for the report that I am going to generate. I created an app engine that willl be called to generate this report. However, I encounter the error "Error occurred while processing the request. (228,101) PT_CONQRS.CONQRSMGR.OnExecute Name:GetXMLData PCPC:59072 Statement:1309". What could be causing this issue? One cause I am thinking is that the Connected Query not returning any data since I am not able to pass / map the values to the CQ's prompt fields. How is this done in CQ? I've done it in PS Query by using the function SetPSQueryPromptRecord+. I'm trying to search for this function's equivalent in CQ. I was able to search for a workaround (http://mfinchps.blogspot.com/2011/05/how-to-launch-connected-query-xml.html), but I still prefer to have a CQ data source.
    Below is the code that should handle mapping of CQ prompt fields:
    &oConQrsInst = create PT_CONQRS:CONQRSMGR(&OperId, &ReportName);
    &result = &oConQrsInst.Open(&oConQrsInst.Const.InitExisting);
    &CQPromptsArray = &oConQrsInst.QueriesPromptsArray;
    &rcdQryRunParms = CreateRecord(@&PromptRec);
    &sqlSelectQryParms = CreateSQL("%Selectall(:1) WHERE OPRID = :2 AND RUN_CNTL_ID = :3");
    &sqlSelectQryParms.Execute(&rcdQryRunParms, &OperId, &RunControlId);
    /*Loop through the Connected Query "Queries" and fill in each query's prompts as needed*/
    For &arrCtr = 1 To &CQPromptsArray.Len
    &rcdQryPrompts = &CQPromptsArray.Get(&arrCtr).QueryPromptRecord;
    For &i = 1 To &rcdQryPrompts.FieldCount
    While &sqlSelectQryParms.Fetch(&rcdQryRunParms)
    If &rcdQryPrompts.GetField(&i).Name = &rcdQryRunParms.GetField(Field.BNDNAME).Value Then
    &rcdQryPrompts.GetField(&i).Value = &rcdQryRunParms.GetField(Field.BNDVALUE).Value;
    Break;
    End-If;
    End-While;
    End-For;
    &sqlSelectQryParms.Close();
    End-For;
    rem &oRptDefn.SetPSQueryPromptRecord(&rcdQryPrompts);  -> need to have equivalent of this+
    &oConQrsInst.Close();
    Thanks!
    Janet

    i think you have run the code to generate the XML file from your connected query...
    check the following things
    1. Check the Report definition is defined or not for the file that you want generate.
    2. if its defined check the RTF template is present or not.
    3.Check your code in Appengine whether you have mentioned the Report Definition and template name,

  • How to find Query with Running time

    dear frnds,
    I need to find the query details and query execution time from a DB USER. am using oracle 11g. how to generate this report
    please give me any idea.,
    thanks.
    Edited by: Velsjeya on May 14, 2012 1:07 AM
    Edited by: Velsjeya on May 14, 2012 1:07 AM

    Velsjeya wrote:
    thanks a lot,
    here i need to show query running time also...( how many mins that particular query ran) ... please help mePlease do search for the question's answer. V$SQL should be able to show you what you are looking for. Asktom's thread given below discusses the same,
    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:912859800346801944
    Aman....

  • Running total required but with different timing

    Hi All:
    I am using Oracle9i Enterprise Edition Release 9.2.0.6.0
    I want to write a query to display the statistics report with running total.
    I have written following query that return last 60 minutes activities.
    SELECT se.tserv_id,
    sum(decode(eu.category,'I',1,0)) Imp,
    sum(decode(eu.category,'E',1,0)) Exp,
    count(*) Total
    FROM service_events se, equipment_uses eu
    WHERE se.performed BETWEEN trunc(sysdate-60/1440,'mi')
    AND trunc(sysdate,'mi')
    AND se.tserv_id IN ('EXM','GROUNDED')
    AND eu.gkey = se.equse_gkey
    AND eu.category IN ('I','E')
    GROUP BY se.tserv_id;
    now I want to write a query that shows me the result of above query and running total as well
    But the different between current activity and running total is as follows
    Current Activity = Last 60 minutes activity
    Running Total = Total activities from the 08:00 am till sysdate.
    for example if this query executed on 11:00 am then the current activity values must be from 10:00 am to 11:00 am and the running total values must be from 08:00 am to 11:00 am
    The reason for running total starts at 08:00 am is that the shift starts from 08:00 am to next day 07:59 am.
    Can I write one single query for this?
    Similarly running total values must be start from last day 08:00 am to current date and time when I executed this query from 00:00 to 08:00 (12 midnight to 8am)
    if difficult then plz let me know that how can I find that if the time is from 00 hrs to 08 hrs then start time must be the last date 08:00 am to the current date and time.
    Thanks
    Hassan

    Dear Frnak
    Thanks for your reply and help
    Its really did what I want
    I mean to say that the result format is correct but the value of Total_day column is not correct.
    Following is the sample data from 19-Jun-2008 08:00 AM to 20-JUN-2008 08:00 AM
    TSERV_ID  EQUSE_GKEY     PERFORMED
    ===============================================
    EXM       5188958     19-Jun-2008 8:00:32 AM
    EXM       5185586     19-Jun-2008 9:03:34 AM
    EXM       5181960     19-Jun-2008 9:03:35 AM
    EXM       5173333     19-Jun-2008 9:03:35 AM
    EXM       5188263     19-Jun-2008 9:08:49 AM
    GROUNDED  5174055     19-Jun-2008 9:10:29 AM
    GROUNDED  5152887     19-Jun-2008 9:10:29 AM
    GROUNDED  5187512     19-Jun-2008 9:10:29 AM
    GROUNDED  5196303     19-Jun-2008 9:27:41 AM
    EXM       5196370     19-Jun-2008 9:29:50 AM
    EXM       5172045     19-Jun-2008 10:01:23 AM
    GROUNDED  5196269     19-Jun-2008 11:11:29 AM
    GROUNDED  5200219     19-Jun-2008 11:24:39 AM
    GROUNDED  5185246     19-Jun-2008 12:06:30 PM
    GROUNDED  5190134     19-Jun-2008 12:09:27 PM
    GROUNDED  5190475     19-Jun-2008 12:09:27 PM
    GROUNDED  5156065     19-Jun-2008 12:26:49 PM
    GROUNDED  5132287     19-Jun-2008 1:56:44 PM
    EXM       5189203     19-Jun-2008 2:29:17 PM
    EXM       5180158     19-Jun-2008 3:27:03 PM
    EXM       5149310     19-Jun-2008 3:37:31 PM
    EXM       5196303     19-Jun-2008 3:42:48 PM
    EXM       5192768     19-Jun-2008 4:03:51 PM
    EXM       5174055     19-Jun-2008 4:14:23 PM
    EXM       5200231     19-Jun-2008 4:45:51 PM
    EXM       5157151     19-Jun-2008 4:51:06 PM
    EXM       5159930     19-Jun-2008 5:01:36 PM
    EXM       5185237     19-Jun-2008 5:01:37 PM
    EXM       5195434     19-Jun-2008 5:01:37 PM
    EXM       5152887     19-Jun-2008 5:06:49 PM
    EXM       5196269     19-Jun-2008 5:06:49 PM
    EXM       5187512     19-Jun-2008 5:17:26 PM
    EXM       5190134     19-Jun-2008 5:59:24 PM
    GROUNDED  5101919     19-Jun-2008 6:44:36 PM
    GROUNDED  5101918     19-Jun-2008 6:44:37 PM
    GROUNDED  5101913     19-Jun-2008 6:44:37 PM
    EXM       5185735     19-Jun-2008 6:46:38 PM
    GROUNDED  5195475     19-Jun-2008 6:47:11 PM
    GROUNDED  5195361     19-Jun-2008 6:47:12 PM
    EXM       5132608     19-Jun-2008 7:02:23 PM
    GROUNDED  5195334     19-Jun-2008 7:10:32 PM
    GROUNDED  5190558     19-Jun-2008 7:10:32 PM
    EXM       5183029     19-Jun-2008 7:33:53 PM
    EXM       5183480     19-Jun-2008 7:39:12 PM
    EXM       5189566     19-Jun-2008 8:00:11 PM
    EXM       5181825     19-Jun-2008 8:15:57 PM
    EXM       5183537     19-Jun-2008 8:15:57 PM
    EXM       5180210     19-Jun-2008 9:08:27 PM
    GROUNDED  5193136     19-Jun-2008 9:58:23 PM
    EXM       5171510     19-Jun-2008 10:21:59 PM
    EXM       5185615     19-Jun-2008 10:48:14 PM
    EXM       5184737     19-Jun-2008 10:53:29 PM
    EXM       5195475     19-Jun-2008 11:51:16 PM
    EXM       5195476     20-Jun-2008 12:01:46 AM
    EXM       5190558     20-Jun-2008 12:12:17 AM
    EXM       5196473     20-Jun-2008 12:54:19 AM
    EXM       5183204     20-Jun-2008 1:20:34 AM
    GROUNDED  5192844     20-Jun-2008 1:28:24 AM
    GROUNDED  5174238     20-Jun-2008 1:28:24 AM
    GROUNDED  5193127     20-Jun-2008 1:28:24 AM
    GROUNDED  5185794     20-Jun-2008 1:29:09 AM
    GROUNDED  5192895     20-Jun-2008 3:04:23 AM
    GROUNDED  5193039     20-Jun-2008 3:04:23 AM
    GROUNDED  5195447     20-Jun-2008 3:04:23 AM
    GROUNDED  5190228     20-Jun-2008 3:04:24 AM
    GROUNDED  5179370     20-Jun-2008 3:04:24 AM
    GROUNDED  5190289     20-Jun-2008 3:04:24 AM
    GROUNDED  5174065     20-Jun-2008 3:04:24 AM
    GROUNDED  5192862     20-Jun-2008 5:04:42 AM
    GROUNDED  5199903     20-Jun-2008 5:04:42 AM
    EXM       5178176     20-Jun-2008 6:30:29 AM
    EXM       5185161     20-Jun-2008 6:46:14 AM
    EXM       5180226     20-Jun-2008 6:46:14 AM
    GROUNDED  5202026     20-Jun-2008 7:03:14 AM
    EXM       5101912     20-Jun-2008 7:07:14 AM
    GROUNDED  5176763     20-Jun-2008 7:25:27 AM
    GROUNDED  5185494     20-Jun-2008 7:25:27 AM
    EXM       5185295     20-Jun-2008 7:38:46 AM
    EXM       5173837     20-Jun-2008 7:49:15 AM
    GKEY     CATEGORY
    =================
    5101912     I
    5101913     I
    5101918     I
    5101919     I
    5132287     I
    5132608     I
    5149310     I
    5152887     I
    5156065     I
    5157151     I
    5159930     I
    5171510     I
    5172045     I
    5173333     I
    5173837     I
    5174055     I
    5174065     I
    5174238     I
    5176763     I
    5178176     I
    5179370     I
    5180158     I
    5180210     I
    5180226     I
    5181825     I
    5181960     I
    5183029     I
    5183204     I
    5183480     I
    5183537     I
    5184737     I
    5185161     I
    5185237     I
    5185246     I
    5185295     I
    5185494     I
    5185586     I
    5185615     I
    5185735     I
    5185794     I
    5187512     I
    5188263     I
    5188958     I
    5189203     I
    5189566     I
    5190134     I
    5190228     I
    5190289     I
    5190475     I
    5190558     I
    5192768     I
    5192844     I
    5192862     I
    5192895     I
    5193039     I
    5193127     I
    5193136     I
    5195334     I
    5195361     I
    5195434     I
    5195447     I
    5195475     I
    5195476     I
    5196269     I
    5196303     I
    5196370     I
    5196473     I
    5199903     I
    5200219     E
    5200231     E
    5202026     EAnd I used the same query suggested by you.
    WITH     s     AS(     
    SELECT     se.tserv_id     ,     eu.category     ,
               CASE
                 WHEN     se.performed     BETWEEN     
                                    to_date('&target_dt','DD-MON-RRRR HH24:MI') - (1/24)
                                  AND     to_date('&target_dt','DD-MON-RRRR HH24:MI')
                          THEN     1
              ELSE     0
              END     AS in_hour     ,
            CASE
              WHEN     TRUNC (se.performed - (8/24)) =     TRUNC (to_date('&target_dt','DD-MON-RRRR HH24:MI')
                                                     - (8/24))
                THEN     1
              ELSE     0
              END     AS in_day
    FROM     service_events     se     ,     equipment_uses     eu
    WHERE     eu.gkey          = se.equse_gkey
         AND     eu.category     IN ('I', 'E')
      AND se.tserv_id in ('EXM','GROUNDED')
    SELECT     tserv_id,     
            SUM (DECODE (category, 'I', in_hour))     AS imp_hour,     
            SUM (DECODE (category, 'E', in_hour))     AS exp_hour,
            SUM (in_hour)     AS total_hour,
            SUM (in_day)     AS total_day
    FROM     s
    GROUP BY     tserv_idNow you have the sample data for almost 24 hours
    Let me clear it again
    When I executed this query at 20-JUN-2008 09:00 AM it gives me following result (that is accurate)
    TSERV_ID  IMP_HOUR  EXP_HOUR  TOTAL_HOUR  TOTAL_DAY
    EXM        2         0           2               3
    GROUNDED   1         0           1               8When I executed this query between 20-JUN-2008 00:00 to 20-JUN-2008 08:00
    then system must show the Total_Day value from 19-JUN-2008 08:00 to current date and time. e.g
    I executed this query at 20-JUN-2008 06:00 AM it gives me following result:
    TSERV_ID  IMP_HOUR  EXP_HOUR  TOTAL_HOUR  TOTAL_DAY
    EXM             0     0     0        44
    GROUNDED     2     0     2        35Now here you can see that the value of Total_Day is not as accurate as I required:
    EXM = 44 and GROUNDED = 35
    these values are between 19-JUN-2008 00:00 to 20-JUN-2008 06:00 (that is wrong in my case)
    The values of total_day should be as follows as 8 hours from 00:00 to 07:59 AM fall in the shift of 18-JUN-2008 not in 19-JUN-2008
    From 19-JUN-2008 08:00 to 20-JUN-2008 06:00
    EXM: 38
    GROUNDED: 32
    Plz note that this result is required because in our company the shift starts from 08:00 AM and ends 07:59 AM next day
    I hope you will be more clear now and there is no confusion anymore.
    Plz let me know if you still confused.
    Brgs,

  • Running totals in crystal designer

    Hi all!
    I want to create a report with running total, that accumulate Balance value for each page.
    Total accumulate should be reseted on each new page.
    I have a query for report: SELECT CardCode, CardName, Balance FROM OCRD.
    And i want a running total for field "Balance" (this total should be reseted on each new page).
    In Crystal Designer I create new Running Total Field (in the PageFooter section).
    In the Editing Running Total window I fill the following sections:
    1) Summary section. Field to summarize: "Command.balance". Type of summary: "sum".
    2) Evaluate section. On change of field: "command.cardcode"
    3) Reset section. I want to choose PageNumber in the field "on change of field". But there is no any special field in the section "Available tables and fields"
    How to reset the running total on each new page?
    Thanks in advance

    Hi all!
    The problem can be solved with report formulas. Probably this information will be useful to somebody.
    So, we have the following task: need to calculate subtotals on each page.
    Let's look at the solution.
    On the first step, create Formula fields:
    1) InitPageSum field has formula:
         WhilePrintingRecords; NumberVar PageSum := 0;
    2) CalcPageSum field has formula:
         WhilePrintingRecords;
         numberVar PageSum := PageSum + {Command.LineTotal}; // I use command to get field-values from //database
         numberVar PageSum
    3) PageBalance field has the following formula:
         WhilePrintingRecords; numberVar PageSum
    On the second step we place formula-fields in report sections.
    1) Variables initialization.
    Insert section in PageHeader area (lets name this section PHa). Drag formula InitPageSum into PHa for zeroing PageSum for each page. Then suppress the section PHa.
    2) Increasing subtotal on page.
    Create additional section in Details area (Dc). Drag CalcPageSum formula-field on this section (Dc). PageSum variable will be increasing in each line. Suppress the section Dc.
    3) Display results.
    a) Insert additional section in PageFooter area (let's name it PFa). Drag PageBalance formula-field into this section (PFa). The section PFa should be displayed on each page of the report, except the last page. The formula is:
    if PageNumber  <>  TotalPageCount then true else false.
    b) Insert additional section in ReportFooter area (let's name it RFa) and make this section the first section of the Report Footer area. Drag PageBalance formula-field into the section RFa. The section RFa should be displayed on the last page only. So, for the Suppress property of this section, create the formula:
    if PageNumber  =  TotalPageCount then true else false
    We make this adjustment (additional section in report footer area) because we need subtotals directly under the report (and not at the bottom of the page)
    Best regards,
    Katrine

  • Running Total and In Current Year Columns Source

    Hi all,
    What is the source for Running Total and In Current Year Columns from Absence Detail Screen.
    From Which tables can I get the information on those columns.
    Thanks in Advance

    Hello,
    I am still struck with Running Total Column
    When i fetch running total using this query it works for some of the employees
    SELECT SUM(ABSENCE_hours) from PER_ABSENCE_ATTENDANCES where person_id = <your person id> and absence_attendance_type_id = <your absence type id>
    As there are three different cases here as Days,Hours and No Balance
    I am missing the logic again here when it comes for no balance and days
    Thanks

  • Running totals by field

    I am trying to create a recap document for a survey. Where you enter the results in individual fields....the same field keeps a running total after entering each number....i did this first in excell.....the field code was RT=0 for excell.....am lost how to make this happen in adobe livecycle design....please help someone.........

    Hi,
    If I got it right, you would like to use 'Record Sort Expert' with running total fields. In this case, you cannot sort by running total fields using 'Record Sort Expert' because of the way Crystal Reports processes the report (three-pass reporting method).
    When a report is created, the 'three-pass reporting method' should be taken into consideration to avoid inconsistencies.
    Further information on this reporting method is available in Crystal Reports Online Help (From Crystal Reports, press F1).
    I hope this helps,
    Selenia

  • Running Total Variation Query Time Optimization

    Hi all, 
    I've been struggling with this query for a while. I need to set a customer specific running total for 10 million rows (reset for every customer). But every time the number goes negative, I need to set it as zero.
    For example,
    member no              amount            wallet
    member1                 400                      400
    member1                 -500                     0
    member1                  200                    200
    member2                  700                    700
    member2                 -200                    500
    Query:
    DECLARE @member float
    DECLARE @prev_member float
    DECLARE @amount float
    DECLARE @wallet float
    DECLARE db_cursor CURSOR FOR  
    SELECT [Member no], [Transaction Amount] 
    FROM [wallet_master_3]
    ORDER BY [Member No], [rownum]
    FOR UPDATE
    OPEN db_cursor
    FETCH NEXT FROM db_cursor INTO @member, @amount
    SET @prev_member = @member
    set @wallet=0
    WHILE @@FETCH_STATUS = 0
    BEGIN   
           IF @prev_member <> @member set @wallet=0
           SET @wallet = @wallet + @amount
           IF @wallet < 0 SET @wallet = 0
           UPDATE [wallet_master_3] SET walletsize = @wallet
           WHERE CURRENT OF db_cursor
           set @prev_member=@member
           FETCH NEXT FROM db_cursor INTO @member, @amount
    END   
    CLOSE db_cursor   
    DEALLOCATE db_cursor
    I've tried using a cursor. In five minutes, it ran 17,000 rows but after running it for 15 hours, the code only manages to set the running total for 175,000 rows. I'm not exactly sure why. Is there a faster approach I can use? 
    Thanks!

    As an exercise a 'Quirky Update' may help you in this scenario. Try the below trick!
    DECLARE @Wallet AS TABLE
    MemberNo VARCHAR(10),
    RowNum INT,
    Amount INT,
    Wallet INT
    INSERT INTO @Wallet (MemberNo, RowNum, Amount) VALUES
    ('member1',1, 400),
    ('member1',2, -500),
    ('member1',3, 200),
    ('member2',1, 700),
    ('member2',2, -200)
    DECLARE @RunTotal AS INT
    UPDATE W1
    SET
    @RunTotal = W1.Wallet =
    CASE
    WHEN W1.RowNum = 1 THEN W1.Amount
    WHEN @RunTotal + COALESCE(W1.Amount, W2.Amount) < 0 THEN 0
    ELSE @RunTotal + COALESCE(W1.Amount, W2.Amount)
    END
    FROM @Wallet W1
    LEFT OUTER JOIN @Wallet W2
    ON W1.MemberNo = W2.MemberNo AND W2.RowNum = W1.RowNum - 1;
    SELECT * FROM @Wallet;
    RESULT
    MemberNo RowNum Amount Wallet
    member1 1 400 400
    member1 2 -500 0
    member1 3 200 200
    member2 1 700 700
    member2 2 -200 500
    You can read more on 'Quirky Update' in below articles
    Solving the Running Total and Ordinal Rank Problems - Jeff Moden
    Robyn Page's SQL Server Cursor Workbench
    NOTE: Please test it thoroughly before using in a production environment!
    Krishnakumar S

  • 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

  • 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

  • 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.

  • How can I display the vendor associated with result of my running total sum

    I have a report that lists vendors with their most vecent order dates.  I need to set up a rotation so that the vendor with the latest order date is next to be selected.  I used the running total summary to pick the latest date.  How can I display the vendor associated with result of my running total summary?

    If your "latest" order date means the "oldest" order date, why don't you try this:
    Go to Report tab -> Record Sort Expert -> Choose your order date in ascending order
    This will make your oldest order your first record shown. 
    You can then create a running total count for each record.
    Lastly, in your section expert under conditional suppress X+2 formula, write this:
    {#CountRecords}>1
    The result will only show the oldest record in your report.
    I hope that helps,
    Zack H.

Maybe you are looking for

  • Sync multiple (but not all) photo folders?

    I've got a new 4G Touch and I am trying to figure out how to sync multiple folders containing pics to the iPod, preserving the folder structure on the PC to the Album structure on the iPod. My device allows the following: 1) Sync all photos from Phot

  • [Goods Receipt PO - Rows - Tax Code][line: 1]

    Dear All,         At the time of opening GRPO and Delivery Document suddenly system giving one error Number was used up in this sequence [Message 80071-20]         And after it I entering required data in GRPO with any tax code then system giving new

  • Tablespace Complete Restore problem.

    Hi Team, I am working on the Oracle 9i tablespace backup & restore operation. For backup I am using the following script. run BACKUP TABLESPACE 'CWMLITE' INCLUDE CURRENT CONTROLFILE FORMAT 'C:\BK\CWMLITE_%d_01'; BACKUP TABLESPACE 'DRSYS' INCLUDE CURR

  • Having issues with Adobe Acrobat X.

    I have the creative suite adobe design and web premium cs6. Adobe acrobat stops working every couple of months and i have to uninstall and reinstall. Is there a better way of fixing this issue?

  • Endless loop with WHILE ?

    Hi Fox, The bellow coding should terminate the function after a certain time in seconds (as input parameter) and displays the variable count. But it terminates at the end with the short dump since the count becomes an overflow. Thanks for you help. F