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

Similar Messages

  • How can i use this expression in DECODE function?

    My PNO table formart is
    PNO PDate PCount
    P001 08/27/05 09:45 20
    P001 08/27/05 09:50 10
    P002 08/27/05 03:40 20
    P003 08/28/05 11:00 20
    P003 09/28/05 10:00 20
    P003 08/27/05 11:00 10
    P003 09/27/05 04:00 50
    I want to display total pcount for shift1(morning) and shift2(evening) & the date is 08/27/05
    PNO Shift1(08/27/2005 08:00 to 12:30) Shift2(08/27/2005 02:00 to 05:30)
    P001 30 0
    P002 0 20
    P004 10 50
    So for shift1 condition is:
    pdate>=08/27/2005 08:00 and pdate<=08/27/2005 12:30
    So for shift2 condition is:
    pdate>=08/27/2005 02:00 and pdate<=08/27/2005 05:30
    If i tried to give this expression in decode function , its not working.
    Please give me the sql query to solve this problem.
    Millions of thanks in advacne

    forgot to paste the output for a given date.
    SQL> create table pno
      2  (pno    varchar2(32)
      3  ,pdate  date
      4  ,pcount number)
      5  /
    Table created.
    SQL>
    SQL> insert into pno values('P001', to_Date('08/27/05 09:45', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P001', to_Date('08/27/05 09:50', 'mm/dd/yy hh:mi') ,10)
      2  /
    1 row created.
    SQL> insert into pno values('P002', to_Date('08/27/05 03:40', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL>
    SQL> insert into pno values('P003', to_Date('08/28/05 11:00', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('09/28/05 10:00', 'mm/dd/yy hh:mi') ,20)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('08/27/05 11:00', 'mm/dd/yy hh:mi') ,10)
      2  /
    1 row created.
    SQL> insert into pno values('P003', to_Date('09/27/05 04:00', 'mm/dd/yy hh:mi') ,50)
      2  /
    1 row created.
    SQL> select pno,sum(pcount) "Morning Shift Count"
      2  from pno
      3  where to_char(pdate, 'mm/dd/yyyy hh:mi') >= '08/27/2005 08:00'
      4    and to_char(pdate, 'mm/dd/yyyy hh:mi') <='08/27/2005 12:30'
      5  group by pno
      6  /
    PNO                              Morning Shift Count                           
    P001                                              30                           
    P003                                              10                           
    SQL> select pno,sum(pcount) "Evening Shift Count"
      2  from pno
      3  where to_char(pdate, 'mm/dd/yyyy hh:mi') >= '08/27/2005 02:00'
      4    and to_char(pdate, 'mm/dd/yyyy hh:mi') <='08/27/2005 05:30'
      5  group by pno
      6  /
    PNO                              Evening Shift Count                           
    P002                                              20                           

  • Error while replacing IF statements with DECODE function in procedure

    Hi All,
    I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
    Procedure:
    IF (var_int_sev = '0')
    THEN
    var_sev := '2';
    ELSE
    SELECT sev
    INTO var_int_sev
    FROM errorconfig
    WHERE errorcode = var_errorcode;
    var_sev := var_int_sev;
    END IF;
    I converted the above IF statement into DECODE function as mentioned below:
    var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
    But it throws below error at the select statement used inside DECODE.
    Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
    Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.

    instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
    read this:
    When your query takes too long ...

  • About Decode Function in oracle(on 28th)

    Hi all
    Can i use Decode function with Distinct as following.
    SUM(DISTINCT DECODE(LR.QUESTIONNAIRE_ID,62, L.WORK_SPACE))
    Regards

    Hi,
    The argument to SUM can be any numeric expression, including a DECODE statement that evaluates to a number.
    "SUM (DISTINCT ..." is very suspicious. If you have three rows, with values 1, 1 and 3, the "SUM (DISTINCT" is 4. Is that what you want?
    Perhaps your problem is that whenever you have more than one row, they will always be identical (e.g., a one-to-may join), so you have rows with 1, 1, and 1, from which you want to return 1. Most people do that by adding the value to the GROUP BY list, or by using MAX or MIN instead of SUM: they get the same results, but the code is clearer, and it works on non-numeric columns.

  • 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 convert rows into columns with decode function

    Hi,
    How to convert rows into columns with the help of decode function in oracle.
    thanks and regards
    P Prakash

    say
    col1 col2
    1 10
    2 20
    3 30
    then use
    select col1,
    sum(decode(col2,10,10)) "new1"
    sum(decode(col2,20,20))"new2"
    sum(decode(col2,30,30))"new3"
    from table_name
    group by col1;
    we used sum u can use ny function if wont u have to give the column name i.e col2 name also
    so i think u got it nw
    regards

  • Group by and decode function

    Can I use a group by on a decode?
    I am using the sql below and get an error message when I
    try to use the group by on a decode.
    select decode(assignment.catcodeid,
    'D', 'SERVICE REQUESTS AND MAINTENANCE',
    'U', 'SERVICE REQUESTS AND MAINTENANCE',
    'P', 'SERVICE REQUESTS AND MAINTENANCE',
    'E', 'SERVICE REQUESTS AND MAINTENANCE',
    'R', 'SERVICE REQUESTS AND MAINTENANCE',
    'T', 'EDUCATION',
    'O', 'OVERHEAD',
    'L', 'UNPAID LEAVE',
    'V', 'VACATION',
    'S', 'SICK PAY',
    'H', 'HOLIDAY',
    'C', 'COMP TIME',
    'UNKNOWN ACTIVITY') "ACTIVITY",
    assignment.catcodeid, assignment.esthrs,
    SUM(ASSIGNMENT.ESTHRS)
    FROM ASSIGNMENT
    GROUP BY ACTIVITY, catcodeid, esthrs
    The error is
    ORA-00904: "ACTIVITY": invalid identifier
    It is understood that Activity is not a field
    on the table.
    But, is there a way that I can group by the result of
    a decode function or what other method/advice I can use to
    group by the result of this.
    Thanks is advance.

    Hello
    You just need to put the decode statement in the group by as well, you can't just use the alias...And if you just group by the catcodeid, you won't be putting all of the SERVICE REQUESTS AND MAINTENANCE rows together. But, because you are selecting the catcodeid aswell as decoding it, that will happen anyway.
    HTH

  • Logical Operations in SQL decode function ?

    Hi,
    Is it possible to do Logical Operations in SQL decode function
    like
    '>'
    '<'
    '>='
    '<='
    '<>'
    not in
    in
    not null
    is null
    eg...
    select col1 ,order_by,decode ( col1 , > 10 , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 , <> 10 , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 , not in (10,11,12) , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 ,is null , 0 , 1)
    from tab;
    Regards,
    infan
    Edited by: user780731 on Apr 30, 2009 12:07 AM
    Edited by: user780731 on Apr 30, 2009 12:07 AM
    Edited by: user780731 on Apr 30, 2009 12:08 AM
    Edited by: user780731 on Apr 30, 2009 12:08 AM
    Edited by: user780731 on Apr 30, 2009 12:09 AM

    example:
    select col1 ,order_by,case when col1 > 10 then 0 else 1 end
    from tab;
    select col1 ,order_by,case when col1 &lt;&gt; 10 then 0 else 1 end
    from tab;
    select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
    from tab;As for testing for null, decode handles that by default anyway so you can have decode or case easily..
    select col1 ,order_by,decode (col1, null , 0 , 1)
    from tab;
    select col1 ,order_by,case when col1 is null then 0 else 1 end
    from tab;

  • SQL Expression in decode function or case statement?

    Can I put SQL expressions in decode function or case statement?
    For example,
    select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
    from element le;
    or
    select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
    ELSE 'Y'
    from element le;
    None of the above work.
    Can anyone tell me how to make it work?
    Is there any workaround?
    Thanks,
    J

    You simply needed and END to your CASE statement;
    SQL> with profile_data as (
       select 'XXXX_AFTER' name, 1 object_id from dual),
         element as (
       select 1 profile from dual union all
       select 2 from dual)
    select le.profile,
       case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
       THEN 'N'
       ELSE 'Y'
       END new_col
    from element le
       PROFILE N
             1 Y
             2 N

  • SQL DECODE function

    Oracle version: 9.2.0.1.0
    Procob version: 9.2.0.1.0
    Cobol version: 3.1.11
    O.S. version: Windows XP
    We have a pro*cobol file with the next conversion rule into a select defined with a cursor.
    NVL(TO_CHAR(A.F_ALTA,'YYYYMMDD'),' '),     
    NVL(TO_CHAR(A.F_ESTADO,'YYYYMMDD'),' '),
    we store the result data through a fetch of the cursor into two variables (W-F-ALTA and W-F-ESTADO) When the program executes an insert of these two values in a target table, we define the next conversion rule:
    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')
    Pro*Cobol and Cobol does not have errors when we precompile and compile the program but, when we execute the generated exe file, Oracle displays the next error:
    ORA-01841 (full) year must be between -4713 and +9999, and not be 0
    We think that the DECODE function is not understood by the cobol or pro*cobol interpreter. If we execute the same code without the DECODE function (only with TO_DATE function) there is no errors in the execution of the program
    somebody knows if there are reported problems with this DECODE function in Pro*Cobol or Cobol and how to solve them?
    Thanks

    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')The problem is with the input values of :W-F-ALTA and :W-F-ESTADO. Using the first line as an example, what you are saying is if :W-F-ALTA is ' ', substitute it with NULL, any other value should be :W-F-ALTA, then output the TO_DATE value of whatever the result is.
    So if the value of :W-F-ALTA is the wrong charater or in the wrong input format, TO_DATE function does not understand it.
    See examples of success and failures below with your Bind variables substituted with typical values.
    SQL> select TO_DATE(DECODE(' ',' ',NULL,'20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    SQL> select TO_DATE(DECODE('1999-01-01',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    SQL> select TO_DATE(DECODE('20060830',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

  • Regarding decode function

    Hi all,
    i want to know abt decode function in oracle-sql
    i..e passing the parameters in decode using decode using ":" bind parameter
    select JOB, decode(:j,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP;
    i declared the j variable in sql environment
    VARIABLE J VARCHAR2(20);
    i exec the query
    and passed as the clerk as input parameter
    but iam getting the o/p as
    JOB DECODE(:J
    MANAGER MANAGER
    MANAGER MANAGER
    MANAGER MANAGER
    SALESMAN SALESMAN
    SALESMAN SALESMAN
    SALESMAN SALESMAN
    CLERK CLERK
    SALESMAN SALESMAN
    ANALYST ANALYST
    CLERK CLERK
    ANALYST ANALYST
    JOB DECODE(:J
    CLERK CLERK
    12 rows selected.
    SQL> PRINT J;
    J
    im not getting o/p
    so please hlelp me only : should be used not &
    this is my first thread.
    execuse me if any mistakes
    tons of thanks in advance to all

    SORRY DAVE,ROD FOR NOT BEING CLEAR,
    IAM WORKING WITH EMP TABLE THE DATA IN IT IS LIKE THIS
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
    7782 CLARK MANAGER 7839 09-JUN-81 2450 10
    7566 JONES MANAGER 7839 02-APR-81 2975 20
    7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
    7499 chaitu SALESMAN 7698 20-FEB-81 1600 300 10
    7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
    7900 JAMES CLERK 7698 03-DEC-81 950 30
    7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
    7902 FORD ANALYST 7566 03-DEC-81 3000 20
    7369 SMITH CLERK 7902 17-DEC-80 800 20
    7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
    7876 ADAMS CLERK 7788 12-JAN-83 1100 20
    AND I USED DECODE FUNCTION
    select JOB BEFOREPROMOTION, decode(job,'CLERK','MANAGER','ANALYST','EXEC') PROMOTION FROM EMP
    BEFOREPRO PROMOTI
    MANAGER
    MANAGER
    MANAGER
    SALESMAN
    SALESMAN
    SALESMAN
    CLERK MANAGER
    SALESMAN
    ANALYST EXEC
    CLERK MANAGER
    ANALYST EXEC
    I..E ALL THE CLERKS TO MANAGERS AND SAME THING WITH ANALYST
    OK
    NOW I WILL SHOW U ANOTHER QUERY
    select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job;
    Enter value for job: 'CLERK'
    old 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job=&job
    new 1: select job,decode(job,'CLERK','MANAGER','ANALYST','EXEC',JOB) FROM EMP where job='CLERK'
    JOB DECODE(JO
    CLERK MANAGER
    CLERK MANAGER
    CLERK MANAGER
    HERE OBSERVE THAT I PASSED JOB ='CLERKS AS PARAMETER AFTER EXECUTING THE QUERY
    IT ASKED LIKE THIS AND SHOWED THE REPLACED VALUES
    Enter value for job: 'CLERK'
    AS SHOWN ABOVE
    FOR THIS TO PASS VALUE
    IN TO THE QUERY BY USING AMPERSAND('&')
    TO TAKE INPUT AS CLERK
    IT CHECKED AND RETURNED THE VALUE
    IN THE SIMILAR WAY CAN I USE ":" COLON
    TO PASS PARAMETERS
    IN TO THE QUERY
    CAN I USE IT
    REGARDS,
    PHANI
    Edited by: user10652894 on Nov 26, 2008 3:24 AM

  • Using DECODE Function to change data

    I am trying to use the Decode function in a SQL statement to find a field that has a specific type, and when it finds that type, I want to blank out the results in a different field.
    For example:
    DECODE(ADDR_TYPE,'HOME',PHONE='') HOME_PHONE

    something like:
    SQL> with t as
      2   (select 219 id,
      3           'BUS' addr_type,
      4           '505-555-5555' phone
      5      from dual
      6    union
      7    select 219 id,
      8           'HOME' addr_type,
      9           null   phone
    10      from dual
    11    union
    12    select 220 id,
    13           'BUS' addr_type,
    14           '101-111-1111'   phone
    15      from dual
    16    union
    17    select 220 id,
    18           'HOME' addr_type,
    19           null   phone
    20      from dual
    21    union
    22    select 223 id,
    23           'BUS' addr_type,
    24           '202-222-2222'   phone
    25      from dual
    26    union
    27    select 224 id,
    28           'HOME' addr_type,
    29           '303-333-3333'   phone
    30      from dual
    31    union
    32    select 225 id,
    33           'BUS' addr_type,
    34           null   phone
    35      from dual
    36    union
    37    select 226 id,
    38           'HOME' addr_type,
    39           null   phone
    40      from dual)
    41  select a.id,
    42         a.addr_type,
    43         decode(a.addr_type,'BUS',phone,null) phone
    44    from (select id, addr_type, phone,
    45                 row_number() over (partition by id order by id, decode(addr_type,'BUS',1,2)) rn
    46            from t) a
    47   where a.rn = 1;
            ID ADDR PHONE
           219 BUS  505-555-5555
           220 BUS  101-111-1111
           223 BUS  202-222-2222
           224 HOME
           225 BUS
           226 HOME
    6 rows selected.
    SQL>

  • PL/SQL URL decode function

    I am looking for a pl/sql url decode function. Does not appear to be in owa_util or htp/htf. Does any one have one please?

    You can use the utl_url package that provides public APIs for both encoding and recoding purposes.

  • How to use Decode Function in Webi / Designer - BOE XI 3.1

    Hi All,
    I have a SQL query which needs to include in the webi report.
    Below is the query :
    SELECT
    SECURITY.SEC_CUSIP_NO "CUSIP", 
    SECURITY.STY_SEC_TY_CD "SECURITY TYPE",
    SECURITY.SEC_DERIVED_DESC_TX "SECURITY DESCRIPTION",
      SECURITY.sec_dep_teleg_de "FED DESCRIPTION",
      SEC_STND_PR "STANDARD/FACTORED PRICE",
      SEC_STND_PR_EFF_DT "STANDARD/FACTORED PRICE Date",
      SECURITY.SEC_YIELD_PR "YIELD PRICE",
      SECURITY.SEC_YIELD_PR_DT "YIELD RICE EFFECTIVE DATE",
      STND_PR_VND_VENDOR_CD "PRICE SOURCE",
      SEC_MATURITY_DT "MATURITY DATE",
      SEC_ISSUE_DT "ISSUE DATE",
                 CASE WHEN SECURITY.STY_SEC_TY_CD IN ('BA','CD','CDD','CDE','CDM','CDV','CP','CPD') THEN
                    (position.PSN_AVAIL_PAR_VL + position.PSN_COLLAT_PAR_VL) * (SECURITY.SEC_STND_PR) / 100
                 ELSE
                    (position.PSN_AVAIL_PAR_VL + position.PSN_COLLAT_PAR_VL) * (  (  SECURITY.SEC_YIELD_PR * DECODE (SECURITY.SEC_PRIN_FT, 0, 1, SECURITY.SEC_PRIN_FT))) / 100
                    * DECODE(SECURITY.STY_SEC_TY_CD, 'AMP', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 'MMP', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 'AMPT', DECODE(NVL(SECURITY.SEC_MULTIPLIER_UNIT_VL,0), 0, 1, SECURITY.SEC_MULTIPLIER_UNIT_VL), 1 )
                 END
            ) "MARKET VALUE"
    FROM SECURITY SECURITY
       ,   position position
    WHERE STND_PR_VND_VENDOR_CD = 'VT'
    AND SEC_MATURITY_DT > SYSDATE-1
    and SECURITY.sec_sys_id=position.sec_sys_id
    I could create a report which has selected objects and defined where condition from the above query. I have also created a variable for 'when' & 'then' condition but stuck at else part which contains 'DECODE' function.
    Please suggestions how to write the same at the report or designer level.
    Thanks,
    Rameez Shaikh

    Hi Rameez,
    Looking at the query you can create the object directly in the universe, either create two objects one for inner decode and use it in outer case logic. In report it is nothing but nested if logic. For eg.  If(a=b;1;(if(a=c;2;3))
    Thanks
    Gaurav

Maybe you are looking for

  • I wish to upload a PDF file to my website but Firefox 3.6.12 reports it as type application/force-download and NOT application/pdf, WHY?

    My website has been running for many months, and as part of the site users can upload PDF documents to share with others. The last successful upload was 5th Nov, but to-day my upload was rejected because Firefox returned the document type as applicat

  • RE: Java and Forte

    We have no problem using JDK 1.1.5. However, we are using Orbixweb. If you are accessing the applet and the IOR file from the same host (exact host name), then one other possibility is the JVM compatibility for your browser. Using Javasoft's Activato

  • MM/FI - Inventory postings (BSX) Open Item management

    Hello - The accounts used for inventory postings (BSX); should they be marked for open item management or not? Is there an adverse effect if the postings on this accounts are cleared?

  • How to get oracle developer suite 10g cds

    hi, i want to learn oracle developer suite 10g. i did not have net to download that much capacity files from oracle OTN. can u please suggest me where can i get the Developer suite cds in India. please help me Thanks RAM PRASAD

  • PIR Availability Check

    Hello all, We have used strategy 65 in project and defined enough PIRs for planning material. When we create a sale order for a variant, PIR availability check was not confirmed. Why? I checked that PIR availability check for strategy 55 and 56 is do