SUM(DECODE(.................) in OWB???

We have a materialized view that along with other statements has:
Select SSN,...,...,
SUM(DECODE(Depn_info_relationship_code,Null,0,1) Num_dependents,
SUM(DECODE(Depn_info_relationship_code,'AO',1,0) Spouse,
etc.
I have been unable to create this in OWB. Any help greatly appreciated.

Eric,
You can create a materialized view in 2 ways:
- write the query manually, which would be easy, I supposse.
- use the mapping editor to build a materialized view and eventually do a reconcile outbound. In that case, you use mapping operators to define the query. You can use the expression operator to define... a CASE statement (instead of the decode) and cascade using the aggregator. Eventually reconcile outbound to the materialized view.
Hope this helps,
Mark.

Similar Messages

  • Sum & decode function

    i have three products viz :'A' ,'B' ,'C'
    I WANT THE OUTPUT LIKE
    PARTY NAME A B C APR04 A B C MAY04 TOTAL
                             A B C
    XYZ LTD     10 11 11 32 15 4 2 21 25 15 13
    YYY LTD 05 0 5 10 25 8 2 35 30 08 07
    I WANT TO TAKE SUCH OUTPUT FROM APR04 TO MAR05 .
    I TRIED SOMETHING LIKE THIS
    SELECT
    invo_h.PTYCD,PARTY_M.PARTY_N1,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',invo_d.QNTY,0)) APR_04,
    sum(decode(invo_d.prdcd,'A',invo_d.QNTY,0)) "A",
    sum(decode(invo_d.prdcd,'B',INVO_D.QNTY,0)) "B",
    sum(decode(invo_d.prdcd,'C',INVO_D.QNTY,0)) "C",
    sum (INVO_D.QNTY) "TOTAL",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',invo_d.QNTY,0)) MAY_04,
    sum(decode(invo_d.prdcd,'A',invo_d.QNTY,0)) "A",
    sum(decode(invo_d.prdcd,'B',INVO_D.QNTY,0)) "B",
    sum(decode(invo_d.prdcd,'C',INVO_D.QNTY,0)) "C",
    sum (INVO_D.QNTY) "TOTAL"
    FROM INVO_H,INVO_D,PARTY_M
    WHERE INVO_H.INVNO=INVO_D.INVNO
    AND INVO_H.INVDT BETWEEN '01-APR-04' AND '31-MAR-05'
    AND INVO_H.PTYCD=PARTY_M.PARTY_CD
    GROUP BY INVO_H.PTYCD,PARTY_M.PARTY_N1
    BUT IT IS GIVING WRONG OUTPUT. same figures even for month May-04 .
    PLS HELP

    SELECT
    invo_h.PTYCD,PARTY_M.PARTY_N1,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',invo_d.QNTY,0)) APR_04,
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'A',invo_d.QNTY,0),0)) "A",
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'B',INVO_D.QNTY,0),0)) "B",
    sum(decode(to_char(invo_h.INVDT,'MM'),'04',decode(invo_d.prdcd,'C',INVO_D.QNTY,0),0)) "C",
    sum (INVO_D.QNTY) "TOTAL",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',invo_d.QNTY,0)) MAY_04,
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'A',invo_d.QNTY,0),0)) "A",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'B',INVO_D.QNTY,0),0)) "B",
    sum(decode(to_char(invo_h.INVDT,'MM'),'05',decode(invo_d.prdcd,'C',INVO_D.QNTY,0),0)) "C",
    sum (INVO_D.QNTY) "TOTAL"
    FROM INVO_H,INVO_D,PARTY_M
    WHERE INVO_H.INVNO=INVO_D.INVNO
    AND INVO_H.INVDT BETWEEN '01-APR-04' AND '31-MAR-05'
    AND INVO_H.PTYCD=PARTY_M.PARTY_CD
    GROUP BY INVO_H.PTYCD,PARTY_M.PARTY_N1

  • Summing decode amount

    Now that you helped me solve a total problem in a crosstab report I have run into another problem in the same report.
    Given are three of the columns A,B,C in the crosstab report .
    A & B are fields from the folders.
    C is a calculated field: NVL(DECODE(AccountType,'Income',( DECODE(Cc Concatenated Segments,MAX(Cc Concatenated Segments) OVER(PARTITION BY AccountType ),Surplus Budget,0) ),0),0)
    C gives me exactly what I want which is a total in only one of the fields while all the rest are 0. (I think that the reasoning as to why I need that is not relevant here). I do not get a total of Field C (it's always blank) but the user is fine with that.
    My problem is that that there needs to be another field D = C - A + B and I do need the grand total of that Field D.
    The total is always blank. I have tried using to_number and multiplying the fields by 1.0. I have tried defining a new field that is C * 1.0 in order to make sure that it is a number. The AggregationBehavior is 1 as is the AllowAggregationOverRepeatedValues, but the total will always be blank.
    If I remove field C from the calculation then it gives me the sum. In other words Field C is definitely the problem.
    Is this total even possible?
    Thanks.
    Leah

    Hi Leah
    It can be daunting at first but practice makes perfect. I have an extremely analytical brain and I have been lucky to have the ability to extend a calculation by 2 or even 3 steps away from where it currently stands. Most people can generally only accept ideas that are one step away from what they know already. Moving two or three steps away without explaining how it is done loses some people and they generally get cross. What I'm getting at is that moving too many analytic steps at the same time is fraught with danger until the basic calculations are fully understood and no erroneous answers pop out.
    Embedding analytic functions inside other functions is a perfect example of moving more than one step at the same time, thus breaking it down into its atomic parts generally does the trick and the answer usually becomes obvious. I appreciate that I am teaching statistical theory and please forgive me if I get too deep. My major was mathematics and sometimes I get carried away.
    You asked whether MAX has to take a number. The answer if no. It does not have to take a number. You can compute the max of a number, a string or a date. Certainly if you have a MAX calculation embedded into a DECODE that under one set of circulstances produces a number and in another set produces a string then the results may not be what you expect.
    Is the DescrField supposed to contain a number or a string? If it contains numbers but they are stored as strings then the MAX of a set of strings will not always produce the same result as the max of a set of numbers.
    I certainly think you need to break down your formulas into manageable single calculations with separate calcs joining them together.
    Hang on in there because you will find it. It sounds as though you may already have hit on something.
    Best wishes
    Michael

  • Decode vs. Case in OWB Transformation

    Hello all,
    I am trying to count or sum all of Reasons where the value is Test. Here is the code which I would like to covert into OWB transformations:
    sum(decode( REASON ,'Test',1,0) )
    Step 1:
    I tried to use Decode in expression
    (decode( REASON ,'Test',1,0) ) and it gives me following error:
    Line 1, Col 1:
    PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only
    Line 0, Col 1:
    PL/SQL: Statement ignored
    It seems OWB does not recognize Decode. How should I solve the problem? Should i try using Case to substitute the above decode code ? like:
    Case
    when Reason='Test'
    then 'Test'
    End
    Am I doing it right?
    and following this I can use aggregator to Sum(test) for counting/summing all tests. Is there anyway I can use this code: sum(decode( REASON ,'Test',1,0) ) in one transformation? Please let me know.
    Thanks,
    K

    OWB provides case statement in place of decode. OWB does not recognize decode statements(till what i know, and tried out)
    Why dont you first use a filter (on reason='test') and then use an aggregrator transformation, You can put input as the column reason from the filter and make a new column in the output group for summing it.
    Hope i have solved your doubts....
    -Nikita.

  • DECODE(SUM Function Transtype substract

    Hi,
    I am trying to subtract transaction types from a FACT table using SUM & DECODE functions. I need to substract Transtypes (10201, 10206, 10207, 10212) - (10202, 10206, 10207, 10212)
    Query
    SELECT
    D0.campaign_id,
    NVL((NVL(((SUM( DECODE((FACT.transtype_key),(10201),(FACT.Occurred)   , (10206), (FACT.Occurred)   , (10207), (FACT.Occurred)   , (10212), (FACT.Occurred), ( 0) ) ) ) ) , (NULL)) ), ( 0))  -  SUM( DECODE((10202),(FACT.Occurred) , (10206),(FACT.Occurred) , (10207),(FACT.Occurred) , (10212),(FACT.Occurred) ) ) )
    FROM EPIMART.MESSAGES_CME_0_V FACT, EPIMART.campaign_0_V D0
    WHERE FACT.TRANSTYPE_KEY IN (10202, 10207, 10219, 10218, 10210, 10212, 10204, 10201, 10206, 10211)
    AND D0.Campaign_key = FACT.campaign_key
    AND (D0.campaign_id = '33205')
    GROUP BY D0.campaign_id
    SQL*Plus: Release 11.2.0.2.0 Production on Wed Dec 26 19:13:26 2012
    Copyright (c) 1982, 2010, Oracle. All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    Thanks,
    Soph
    Edited by: Soph on Dec 26, 2012 4:15 PM

    Soph wrote:
    Hi Frank,
    So 10206, 10207, and 10212 count as both positive and negative? Only positive
    Why not just say "I need to substract Transtype 10201 - 10202"? That's what I'm trying to accomplish
    Do all the other transtypes mentioned in the WHERE clause (10204, 10210, 10211, 10218 and 10219) count as 0? some of them have count
    Below is a sample output of data the query produced. the unique campaign_id retrieves the number of unique member number in the FACT table then sum per transaction type key event... I basically need the sum of transtype_keys ==> (10201, 10206, 10207, 10212) - (10202, 10206, 10207, 10212)
    CAMPAIGN_ID     SENT     TARGETED     BOUNCED     VIEWED     DUPLICATE     UNDELIVERED     DO_NOT_SOLICIT     UNSUBSCRIBED     NOT_SENT_NO_TRANSLATE     FIELD_IGNORED
    33205     1,221,188     1,296,690     108,223     214,256     75,265     183,725     38     1     199     0
    Desired Result
    Targeted = Sent + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME + Duplicate
    MINUS
    Delivered = Targeted - Do Not Solicit - Duplicate - Bounced - Not Sent No Translate
    SENT 10201
    DO_NOT_SOLICIT_CME 10207
    NOT_SENT_NO_TRANSLATE_CME 10212
    DUPLICATE 10206
    Let me know if something is unclear
    Thanks,
    Soph
    Edited by: Soph on Dec 27, 2012 8:35 AMEverything is unclear. Do you need to have targeted, whatever you call the stuff substracted form targete and delivered appear in the query or just the single result of the subtraction? If just the single number then the whole thing is equivalent to 10201 - 10202. Perhaps this helps explain our confusion, since you did not give a translation for 10202, I labelled it NOT_SURE.
       (SENT     + DUPLICATE + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME)
    - (NOT_SURE + DUPLICATE + DO_NOT_SOLICIT_CME + NOT_SENT_NO_TRANSLATE_CME)everything except sent and not_sure cancel out in the two sums, so why bother adding them in in the first place. Just substutute some actual numbers in that to prove it to yourself.
    Further, you are only using 5 different values of transtype_key in the calulation, yet your in list has 10 different values. Why select those out of the table just to throw them away? It looks to me as if you are showing only part of a larger effort, and the missing bits are what confuses us.
    John

  • OWB Mapping & Errors

    I have the following data:
    Date Service
    2/10/06 1:20:10 Radio
    2/10/06 1:20:11 Radio
    3/29/06 2:20:11 TV
    3/29/06 3:40:17 Radio
    3/29/06 3:40:17 TV
    I want to convert the service column to rows such that I get this result:
    trunc(Date) radio TV
    2/10/06 2     0
    3/29/06     1 2
    So the code is:
    sum(decode(service, 'radio',1,0))
    sum(decode(service, 'tv',1,0))
    I am using unpivot operator to decode column service to rows and then an aggregator to count the radio entry for each day and then an aggregator to group by the result from previous aggregator to group by date, radio, tv. My questions are:
    1) Am i doing this correctly? If not then how else should I do this? If Yes then :
    2) What Execute operation should I used? Set Type, Row Type?
    When I execute, it says rows inserted and completed with errors, but when I go and check if any rows have been populated in my table, it does not show even a single row. Why does it not show any rows? Also it is so confusing to troubleshoot and figure out errors in Oracle Audit Report. Can anyone tell me where to look for errors in audit report?
    Any help should be appreciated
    Thanks

    Ola Kitty7,
    The unpivot seems ok to me. Beside that, if you follow the pivot/unpivot guidelines there is not so much you can do wrong...
    Regarding the second question I'm not quite sure about the unpivot. But I do think that this operator can be used for both modes. Keep in mind that set based in general will be faster. Rowbased however can give you more detailed (error) information in the runtime audit browser (btw: this tool does not give me all the answers when something is going wrong. Digging in the plsql code gives more answers most of the time).
    Within the Audit Browser you can find errors when a load has failed (available in OWB folder under programs). This information is also available in the OWB10G_RT schema. It is stored in system tables. There you can find error information.
    Sometimes it works quite well to check the intermediate results of a single operator (for instance the unpivot operator you mentioned) and execute this in TOAD. Thats how I
    a) solve most of my problems;
    b) check if my result set is ok.
    Good luck and regards,
    Moscowic

  • Comma delimited in Sql query decode function errors out

    Hi All,
    DB: 11.2.0.3.0
    I am using the below query to generate the comma delimited output in a spool file but it errors out with the message below:
    SQL> set lines 100 pages 50
    SQL> col "USER_CONCURRENT_QUEUE_NAME" format a40;
    SQL> set head off
    SQL> spool /home/xyz/cmrequests.csv
    SQL> SELECT
    2 a.USER_CONCURRENT_QUEUE_NAME || ','
    3 || a.MAX_PROCESSES || ','
    4 || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    5 ||sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'I',1,0),0)) Pending_Normal ||','
    6 ||sum(decode(b.PHASE_CODE,'R',decode(b.STATUS_CODE,'R',1,0),0)) Running_Normal
    7 from FND_CONCURRENT_QUEUES_VL a, FND_CONCURRENT_WORKER_REQUESTS b
    where a.concurrent_queue_id = b.concurrent_queue_id AND b.Requested_Start_Date <= SYSDATE
    8 9 GROUP BY a.USER_CONCURRENT_QUEUE_NAME,a.MAX_PROCESSES;
    || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    ERROR at line 4:
    ORA-00923: FROM keyword not found where expected
    SQL> spool off;
    SQL>
    Expected output in the spool /home/xyz/cmrequests.csv
    Standard Manager,10,0,1,0
    Thanks for your time!
    Regards,

    Get to work immediately on marking your previous questions ANSWERED if they have been!
    >
    I am using the below query to generate the comma delimited output in a spool file but it errors out with the message below:
    SQL> set lines 100 pages 50
    SQL> col "USER_CONCURRENT_QUEUE_NAME" format a40;
    SQL> set head off
    SQL> spool /home/xyz/cmrequests.csv
    SQL> SELECT
    2 a.USER_CONCURRENT_QUEUE_NAME || ','
    3 || a.MAX_PROCESSES || ','
    4 || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    5 ||sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'I',1,0),0)) Pending_Normal ||','
    6 ||sum(decode(b.PHASE_CODE,'R',decode(b.STATUS_CODE,'R',1,0),0)) Running_Normal
    7 from FND_CONCURRENT_QUEUES_VL a, FND_CONCURRENT_WORKER_REQUESTS b
    where a.concurrent_queue_id = b.concurrent_queue_id AND b.Requested_Start_Date <= SYSDATE
    8 9 GROUP BY a.USER_CONCURRENT_QUEUE_NAME,a.MAX_PROCESSES;
    || sum(decode(b.PHASE_CODE,'P',decode(b.STATUS_CODE,'Q',1,0),0)) Pending_Standby ||','
    >
    Well if you want to spool query results to a file the first thing you need to do is write a query that actually works.
    Why do you think a query like this is valid?
    SELECT 'this, is, my, giant, string, of, columns, with, commas, in, between, each, word'
    GROUP BY this, is, my, giant, stringYou only have one column in the result set but you are trying to group by three columns and none of them are even in the result set.
    What's up with that?
    You can only group by columns that are actually IN the result set.

  • Decode function and dates

    I have the following query:
    select of_coy,of_div,
    max(DECODE(of_takeon_date, 'MON', 1,0)) JAN,
    max(DECODE(of_takeon_date, 'MON', 1,0)) FEB,
    max(DECODE(of_takeon_date, 'MON', 1,0)) MAR,
    max(DECODE(of_takeon_date, 'MON', 1,0)) APR,
    max(DECODE(of_takeon_date, 'MON', 1,0)) MAY,
    max(DECODE(of_takeon_date, 'MON', 1,0)) JUN,
    max(DECODE(of_takeon_date, 'MON', 1,0)) JUL,
    max(DECODE(of_takeon_date, 'MON', 1,0)) AUG,
    max(DECODE(of_takeon_date, 'MON', 1,0)) SEP,
    max(DECODE(of_takeon_date, 'MON', 1,0)) OCT,
    max(DECODE(of_takeon_date, 'MON', 1,0)) NOV,
    max(DECODE(of_takeon_date, 'MON', 1,0)) DEC
    from mac.oprfile
    where of_takeon_date > to_date('01-01-2010','DD-MM-YYYY')
    GROUP BY of_coy,of_div
    order by 1;
    The output displayed is not what i want as it displays just zeros, what about the counts for the months of JAN,FEB,MAR
    "OF_COY"     "OF_DIV"     "JAN"     "FEB"     "MAR"     "APR"     "MAY"     "JUN"     "JUL"     "AUG"     "SEP"     "OCT"     "NOV"     "DEC"
    01     01     0     0     0     0     0     0     0     0     0     0     0     0
    01     02     0     0     0     0     0     0     0     0     0     0     0     0
    01     03     0     0     0     0     0     0     0     0     0     0     0     0
    01     04     0     0     0     0     0     0     0     0     0     0     0     0
    01     07     0     0     0     0     0     0     0     0     0     0     0     0
    01     08     0     0     0     0     0     0     0     0     0     0     0     0
    01     09     0     0     0     0     0     0     0     0     0     0     0     0
    01     12     0     0     0     0     0     0     0     0     0     0     0     0
    01     22     0     0     0     0     0     0     0     0     0     0     0     0
    02     01     0     0     0     0     0     0     0     0     0     0     0     0
    04     01     0     0     0     0     0     0     0     0     0     0     0     0
    please assist in fixing the sql query

    Hi,
    Use the following query for taking the sum based on the month.
    select of_coy,of_div,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JAN,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) FEB,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) MAR,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) APR,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) MAY,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JUN,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) JUL,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) AUG,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) SEP,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) OCT,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) NOV,
    sum(max(DECODE(of_takeon_date, 'MON', 1,0))) DEC
    from mac.oprfile
    where of_takeon_date > to_date('01-01-2010','DD-MM-YYYY')
    GROUP BY of_coy,of_div
    order by 1;
    ex :- select first_name,department_id,
    sum(decode(to_char(HIRE_DATE,'MON'),'JAN',1,0)) "JAN",
    sum(decode(to_char(HIRE_DATE,'MON'),'FEB',1,0)) "FEB",
    sum(decode(to_char(HIRE_DATE,'MON'),'MAR',1,0)) "MAR",
    sum(decode(to_char(HIRE_DATE,'MON'),'APR',1,0)) "APR",
    sum(decode(to_char(HIRE_DATE,'MON'),'MAY',1,0)) "MAY",
    sum(decode(to_char(HIRE_DATE,'MON'),'JUN',1,0)) "JUN",
    sum(decode(to_char(HIRE_DATE,'MON'),'JUL',1,0)) "JUL",
    sum(decode(to_char(HIRE_DATE,'MON'),'AUG',1,0)) "AUG"
    from emp
    GROUP BY first_name,department_id
    ORDER BY 1;
    Regards,
    NTR

  • A better way to differentiate positive vs. negative numbers and sum them ?

    Hi, I wonder if there is a better or easier way to differentiate the positive numbers from negative ones and sum them respectively?
    I come up with below:
    create table t1 (num number, id varchar2(3));
    insert into t1 values  (-100, 1);
    insert into t1 values (50, 2);
    insert into t1 values  (-10, 3);
    insert into t1 values  (-20, 4);
    insert into t1 values  (50, 5);
    insert into t1 values  (60, 6);
    select sum(decode(sign(num), 1, num, 0)) plus, sum(decode (sign(num), -1, num, 0)) minu from t1;
    PLUS   MINU
    160     -130Any suggestion would be appreciated! Thanks

    if there is a better or easier way to differentiate the positive numbers from negative ones and sum them respectively?Maybe you want them in different rows than in different columns:
    SQL> select sign(num), sum(num) from t1 group by sign(num)
    SIGN(NUM)   SUM(NUM)
             1        160
            -1       -130
    2 rows selected.?

  • Looking for some tips on Decoding date. TX

    HI,I still have problem with this decode. I need to count students group by their region on each month. The output should be
    COUNTRY OCT NOV DEC .....
    USA 5 20 30
    CAN 100 1 0
    MEX 10 20 30
    The date format is 5/19/2007
    This is my code: and thanks for your help
    WITH Q AS (SELECT DISTINCT A.STDID, A.NUMBER, A.ADMIT
    FROM PROG A
    JOIN CITIZEN B ON A.STDID = B.STDID
    JOIN REGION_TBL C ON C.REGION = B.REGION
    AND A.NUMBER = 'PS'
    AND A.ADMIT IN ('2007','2008'))
    SELECT J.REGION, I.DESCR,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '09', 1, 0))) SEP_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '10', 1, 0)))OCT_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '11', 1, 0)))NOV_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '12', 1, 0)) )DEC_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '1', 1, 0)) )JAN_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '2', 1, 0)) )FEB_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '3', 1, 0)) )MAR_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '4', 1, 0)) )ARL_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '5', 1, 0)) )MAY_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '6', 1, 0)) )JUN_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '7', 1, 0)) )JUL_TOTAL,
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '8', 1, 0)) )AUG_TOTAL
    FROM CITIZEN J
    JOIN PROG L ON J.STDID = L.STDID
    JOIN Q ON J.STDID = Q.STDID
    AND Q.NUMBER = J.NUMBER
    GROUP BY J.REGION, I.DESCR

    SUM(DECODE(TO_CHAR(L.ACTION_DT,'YYYY-MM-DD', '09', 1, 0))) SEP_TOTAL,Apart from having brackets in the wrong place you are comparing a date that you are converting to a string in the format YYYY-MM-DD to a string that is 1 or 2 digit number.
    This should be something like
    SUM(DECODE(TO_CHAR(L.ACTION_DT,'MM'),'09',1,0)) as SEP_TOTAL,

  • Oracle 11g SUM function on the result of inner Select

    The inner Select returns rows with the values. The outer select running on tthe result of inner select SUM the result of the inner select.
    Although there are valid rows of the inner select the SUM in the outer SELECT return NVL. As a comment any aggregate function on the outer select returns NVL.
    The query is below.
    select a.yil,
    a.ay,
    sum(brut_prim),
    sum(kom),
    from (SELECT oid_pol_kesilen_acente,
    to_char(pp.zeyil_tanzim_tar, 'yyyy') yil,
    to_char(pp.zeyil_tanzim_tar, 'mm') ay,
    sum(decode(substr(pp.no, 1, 1),
    'T',
    pp.zeyil_brut_prim_fark / 2,
    pp.zeyil_brut_prim_fark)) -
    sum(pp.zeyil_gv_fark) brut_prim,
    sum(pp.zeyil_acente_kom_fark) kom
    from pol_police pp, org_acente oa
    WHERE SUBSTR(PP.NO, 1, 1) != 'D')
    group by oid_pol_kesilen_acente,
    to_char(pp.zeyil_tanzim_tar, 'yyyy'),
    to_char(pp.zeyil_tanzim_tar, 'mm')) a
    group by a.yil, a.ay, oid_pol_kesilen_acente
    Edited by: [email protected] on May 7, 2010 2:09 AM
    Edited by: [email protected] on May 7, 2010 2:31 AM

    Hi,
    please try the below sql:
    select a.yil, a.ay, sum(brut_prim), sum(kom),
    from (SELECT oid_pol_kesilen_acente,to_char(pp.zeyil_tanzim_tar, 'yyyy') yil, to_char(pp.zeyil_tanzim_tar, 'mm') ay,
    sum(decode(substr(pp.no, 1, 1), 'T',nvl(pp.zeyil_brut_prim_fark,0) / 2,nvl(pp.zeyil_brut_prim_fark,0))) - sum(nvl(pp.zeyil_gv_fark,0)) brut_prim,
    sum(nvl(pp.zeyil_acente_kom_fark,0)) kom
    from pol_police pp, org_acente oa
    WHERE SUBSTR(PP.NO, 1, 1) != 'D'
    group by oid_pol_kesilen_acente,
    to_char(pp.zeyil_tanzim_tar, 'yyyy'),
    to_char(pp.zeyil_tanzim_tar, 'mm')
    ) a
    group by a.yil, a.ay, oid_pol_kesilen_acente ;
    Thanks,
    Siva

  • How to use DECODE function in Exspression?

    Hi,
    Can we use DECODE in Expression?
    I'm trying to use DECODE function but there is an error during the validation. But when i validate the mapping, it is successfully compiled but it is failed during deployment.
    But if I use CASE instead of DECODE, it works fine.
    Can we use DECODE in OWB???
    Thanks
    Raj

    Hi,
    In OWB 10gR2, if your are using only one DECODE in an expression, it's working. The package will compile when deploying the mapping. OWB will replace the DECODE by a CASE.
    But when you are using nested decode in an expression ( for example : decode(col1, 1, 'M', decode(col2, 'Madame', 'Mme', null)) ) only the first one is replaced by a case at deployment.
    In ROW_BASED mode, text of the expression is used outside of an sql statement and deployment will fails with "PLS-00204: function or pseudo-column 'DECODE' may be used inside a SQL statement only."
    If operating mode for the mapping is set to SET_BASED, it's working because the expression is used in an sql statement.
    I have logged a SR in metalink for this issue and a bug is opened (bug 5414112).
    But I agree with you, it's better to use case statement.
    Bernard

  • Performing math on Decode function tags and moving averages

    I have a query shown below to create columns for my report. Can I use the field names as shown in bold to perform math functions? Is there an easy way to do this?
    select Data_date,
    SUM(DECODE(tag_id,'SEF_F0348I',avg_value,NULL))"TE_Flow_mgd",
    SUM(DECODE(tag_id,'L_STEbod_con',avg_value,NULL))"TE_BOD_mgl",
    "TE_FLOW_mgd" * "TE_BOD_mgl" * 8.34*.45359 as "KG_BOD"FROM daily_tag_data
    Where data_date >= to_date('12/31/2002','mm/dd/yyyy')
    GROUP BY data_date;
    Also how would I perform a seven day moving average on "KG_BOD"
    Thanks - Very new at this.

    If you want avoid a sub-query, try this...
    select Data_date,
    SUM(DECODE(tag_id,'SEF_F0348I',avg_value,NULL))"TE_Flow_mgd",
    SUM(DECODE(tag_id,'L_STEbod_con',avg_value,NULL))"TE_BOD_mgl",
    SUM(DECODE(tag_id,'SEF_F0348I',avg_value,NULL)) * SUM(DECODE(tag_id,'L_STEbod_con',avg_value,NULL)) * 8.34*.45359 "KG_BOD"
    FROM daily_tag_data
    Where data_date >= to_date('12/31/2002','mm/dd/yyyy')
    GROUP BY data_date;
    just replace the 'column-alias' with the actual arithmetic fuction...

  • How to find the sum of a column

    I need to find the sum of a column and use it in a different column. The following is the example.
    Column names: Feedback(Good, Avg, Poor), Count(no of good, no of avg, no of poor) and %age(Feedback/sum(feedback))
    I want to find the sum in Java class and also calculate the last column in java class.
    Please tell me some way to do it.

    oh.. ok ..thanks for letting me know.. i will formulate the question in a proper way:
    This is what my UI should look like:
    Rating Count Percent
    Excellent 2 20
    Good 6 60
    Poor 1 10
    Bad 1 10
    Now i have the following columns in the data base:
    Meaning and feedback_rating.
    So the following SQL Query:
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    will give me the result as
    rating counted
    Excellent 2
    Good 6
    Poor 1
    Bad 1
    Now I want a third column as percentage : Earlier we were doing this calculation in the sql query itself, so the query was like
    SELECT hrl.meaning rating,
    sum(decode(bcpi.feedback_rating, null, 0, 1)) counted,
    sum(decode(bcpi.feedback_rating, null, 0, 1))/(max (select count (*) from cmp_cwb_person_info bcpi ,
    hr_lookups hrl )) percent
    from cmp_cwb_person_info bcpi ,
    hr_lookups hrl
    group by hrl.meaning
    Hence the third column (percent) was calculated in the sql query itself.
    But now i feel that the performance of the query could be improved if we get the first two columns from the database and the calculate the third column programatically in the java code.
    So this is what I want to know. How can i do that?

  • Sum amount - Positive and negative

    How do I have a select statement that sum up all the negative and positive values into 2 serperate column? sth like this:
    SELECT sum(amount) as negative, sum(amount) as positive FROM account_table WHERE customer_id = 111;Here is how the output look like when I retrieve the amount of customer_id = 111:
    Amount
    1.4
    300
    -1.22
    -100The expected output that I want should be like this:
    Positive          Negative
    301.4                -101.22

    DECODE and SIGN functions can help
    SQL> select * from t
      2  /
           VAL
             1
            -2
             3
            -4
             5
            -6
             7
            -8
             9
           -10
    10 rows selected.
    SQL> select sum(decode(sign(val),1,val)) pos, sum(decode(sign(val),-1,val)) neg
      2    from t
      3  /
           POS        NEG
            25        -30

Maybe you are looking for

  • IDoc not received by the Webmethods

    Dear Abapers, I have a scenario : Here the idoc  is being created perfectly with all the segments prooperly populated.  Also from SAP side, we are getting the message that it has been sent. However, the receiver ( Webemthods) is saying that it is not

  • Shared review using Sharepoint 2010 Foundation

    Brief description * Sharepoint for Shared review Please describe your issue in as much detail as possible * Shared review using server acrobat.com works fine. However, when using Sharepoint as server the testing fails and it is not possible to finnis

  • Video made with Keynote don't work with QuickTime

    I have made 10 seconds animation with Keynote and exported it as a video with the highest resolution (.MOV). The Keynote file includes three slides. All the slides plays with Quicktime 7.6.9 (1680.8) in my old Mac G5 (sys. 10.5.8.) and throughout the

  • Process chain inyellow status.

    HI Experts, I am runnig a process chain.one of the process is activation of DSO.it is succesful.i can see the sucees message in disply messags and manage of the dso i can see the bex symbol.but the process is in yellow for long time.and next process

  • The existing Application Server Installation is corrupted

    Well I downloaded the Java Studio Creator and wanted to test it on a Debian GNU/Linux box. See what happened while installing it: http://people.freenet.de/jtocancipa/jsc2_install_bug_debian.jpg http://people.freenet.de/jtocancipa/install.log.gz Not n