Help - nested Case statement

Hello everyone.  I'm having a hell of a time trying to understand my nested case statement.  It's pretty simple, but I always feel to get this error:

ORA-00937: not a single group group function
* 00937. 00000 - 'not a single-group function. "
Cause:
Action:

However, when I try to enter in a "group by" I get this error:

ORA-00979: not a GROUP BY expression
* 00979. 00000 - 'not a GROUP BY expression. "
Cause:
Action:

I don't know if there is something wrong with my nested case statement syntax, or miss me something more fundamental. This is my code:
SELECT AE.EMP_ID,
  CASE
    WHEN EP.PHYSICAL_DATE IS NULL
    THEN
      CASE
        WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365)
        THEN 'NEEDS PHYSICAL'
        WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330)
        THEN 'COMING UP'
        ELSE 'No'
      END
    WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
    ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365)
    THEN 'NEEDS PHYSICAL'
    WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
    ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330)
    THEN 'COMING UP'
    ELSE 'No'
  END "Needs Physical?"
FROM AP AE
LEFT JOIN EMP_PHYSICAL EP
ON AE.EMP_ID = EP.EMP_ID
LEFT JOIN POSITION_OFFERED PO
ON AE.EMP_ID = PO.EMP_ID
LEFT JOIN EMP_CONTRACT EC
ON AE.EMP_ID         = EC.EMP_ID
WHERE PO.ACTUAL_END IS NULL
AND (EP.PHYSICAL     = 1
OR EP.PHYSICAL      IS NULL)
AND :P71_EMP_ID = AE.EMP_ID;
I appreciate all help. Nice day.

Aqua

SELECT AE.EMP_ID,
CASE
WHEN EP.PHYSICAL_DATE IS NULL
THEN
CASE
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN EC.ORIGINAL_CONTRACT_START < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 365)
THEN 'NEEDS PHYSICAL'
WHEN MAX(EP.PHYSICAL_DATE) KEEP (DENSE_RANK LAST
ORDER BY EP.PHYSICAL_DATE) < ((SYSDATE) - 330)
THEN 'COMING UP'
ELSE 'No'
END "Needs Physical?"
FROM AP AE
LEFT JOIN EMP_PHYSICAL EP
ON AE.EMP_ID = EP.EMP_ID
LEFT JOIN POSITION_OFFERED PO
ON AE.EMP_ID = PO.EMP_ID
LEFT JOIN EMP_CONTRACT EC
ON AE.EMP_ID = EC.EMP_ID
WHERE PO.ACTUAL_END IS NULL
AND (EP.PHYSICAL = 1
OR EP.PHYSICAL IS NULL)
AND :P71_EMP_ID = AE.EMP_ID;
GROUP BY AE.EMP_ID,EP.PHYSICAL_DATE,EC.ORIGINAL_CONTRACT_START;


Hi,

You need to add Group by clause at the end of the query i have added above.

Tags: Database

Similar Questions

  • How can I get the nested case statements to work with listagg?

    I have a statement below that does not work as I want it, here is my code:

    Select

    cases where o.personal_label is not null

    then

    listagg (cases where s.subcodevalue like '% MON %')

    then s.subcodevalue |' '|| o.personal_label

    of other s.subcodevalue

    end,': ')

    the Group (order of s.subcodevalue) as subcodevalue

    on the other

    listagg (s.subcodevalue,': ')

    the Group (order of s.subcodevalue) as subcodevalue

    end

    of mtm_styles_new s, order_mtm o

    where INSTR (o.extras, s.code) > 0

    and o.bodyfitting = s.bodyfitting

    and o.division = s.division

    and s.subcodevalue is not null

    and o.ORDER_MTMID = 'somevalue '.

    It should bring the following

    * MY TEST: RPP

    or the following if the first case is not completed:

    * MONDAY: RPP

    I get an error message saying 'missing keyword', but cannot make out where, can someone please help me here?

    The following works fine as long as it is not a nested case statement, but I need to nest the case statement:

    Select listagg (cases where s.subcodevalue like '% MON %')

    then s.subcodevalue |' '|| o.personal_label

    of other s.subcodevalue

    end,': ')

    the Group (order of s.subcodevalue) as subcodevalue

    of mtm_styles_new s, order_mtm o

    where INSTR (o.extras, s.code) > 0

    and o.bodyfitting = s.bodyfitting

    and o.division = s.division

    and s.subcodevalue is not null

    and o.ORDER_MTMID = 'somevalue ';

    Out alias 'subcodevalue as' the case at the end of the case body.

  • Nested Case statement

    Hello
    I need help implementation of multiple Case statements in a select statement. I can not it works in a statement.
    SELECT statement
    select distinct 
    allt.fk_jobcode_id as Job_Code, 
    allt.fk_jobcode_descr as Classification,
    sum(allt.number_of_positions) as Number_Allotted,
    sum(number_of_positions) as Sum_Number_Allotted,
         dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
        THEN div.division_name  
      END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,
    allt.fund_type as Fund
    from tbl_allotment allt, tbl_department dept, tbl_division div
    where isdeleted <> 'Y'
     and ALLT.FK_DEPARTMENT_ID = dept.department_id
     and ALLT.FK_DIVISION_ID = div.division_id
    group by fk_jobcode_id, fk_jobcode_descr, fund_type, department_name, division_name 
    HAVING (count(fk_jobcode_descr ) = 1)
    order by Classification asc, Department_Division asc
    1st CASE statement combines the Department_Name and Division_Name values, but does not display the Division_Name if the value is "N/a".
         dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
        THEN div.division_name  
      END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,
    value: administrator Office/Administration Council
    value: poster of the administrator of the Office/s/o Board in the Office of the Director of the Board

    I need to extend this now using this CASE statement, which displays the text "Public works" If the department_id = 00072.
         (CASE dept.department_id 
         When '00072' then 'Public Works'
         Else dept.Department_Name
         End) as Department_Name, 
    incorrect: road Rehab program/GLP transport program Admin
    Must fill as: work GLP/public transport program Admin
    select distinct 
    allt.fk_jobcode_id as Job_Code, 
    allt.fk_jobcode_descr as Classification,
    sum(allt.number_of_positions) as Number_Allotted,
    sum(number_of_positions) as Sum_Number_Allotted,
         dept.department_name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
        THEN div.division_name  
      END),'/'||DIV.DIVISION_NAME||'',null) as Department_Division,
      (CASE dept.department_id 
         When '00072' then 'Public Works'
        ELSE dept.Department_Name|| ''||nvl2((CASE WHEN div.division_name <> 'N/A'
        THEN div.division_name  
           END),'/'||DIV.DIVISION_NAME||'',null)
      END) as Department_Name1,
    allt.fund_type as Fund
    from tbl_allotment allt, tbl_department dept, tbl_division div
    where isdeleted <> 'Y'
     and ALLT.FK_DEPARTMENT_ID = dept.department_id
     and ALLT.FK_DIVISION_ID = div.division_id
    group by fk_jobcode_id, fk_jobcode_descr, fund_type, department_name, division_name, department_id 
    HAVING (count(fk_jobcode_descr ) = 1)
    order by Classification asc, Department_Division asc
    but once I change the select statement I get only value "Public works" for the Department_Division value. Does not meet Division_Name data. Does anyone know how to combine these CASE statements? Thanks for reading this thread also.

    Hello

    I think you want something like this:

    SELECT       ...
    ,       CASE
               WHEN  department_id = '00072'
               THEN  'Public Works'
               ELSE  dept.department_name
           END
           ||
           CASE
               WHEN  div.division_name != 'N/A'
               THEN  '/' || div.division_name
           END          AS department_name1
    ...
    

    Whenever you have a problem, post a small example (CREATE TABLE and only relevant columns, INSERT statements) of all database tables.
    Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
    Always tell what version of Oracle you are using.

  • using nested case statement does not get the right result

    Hello all;

    I have a sample of data similar to below
    create table t3
    ( 
           id varchar2(200),
           qty number(30),
           qty2 number(30)
    ); 
     insert into t3
       (id, qty, qty2)
     values
       ('A', 10, null);
     
      insert into t3
       (id, qty, qty2)
     values
       ('A', 20, null);
       
     insert into t3
       (id, qty, qty2)
     values
       ('B', null, 5);
       
    insert into t3
       (id, qty, qty2)
     values
       ('B', null, 5);
       
     insert into t3
       (id, qty, qty2)
     values
       ('C', null, -5);
       
    insert into t3
       (id, qty, qty2)
     values
       ('C', null, 5);
    
    
     insert into t3
       (id, qty, qty2)
     values
       ('D', -1, -2);
       
    insert into t3
       (id, qty, qty2)
     values
       ('D', 1, 4);
    This is what looks like data
    ID  QTY  QTY2
    A    10
    A    20
    B              5
    B              5
    C             -5
    C              5
    D    1        4
    D   -1       -2
    It is the output that I desired below
    ID    Status 
    A      Fail
    B      Fail
    C      Pass
    D      Fail
    A is a failure because the sum of the 2 has the value zero, where the summation of the qty was used to determine the State and because the sum of the quantity is not equal to zero, then, it is a failure
    D is a failure because even if the sum of the Qty 1 equals zero, we must make use of summation of the qty 2 instead because he is not null to determine the status and the summation of the qty is 2, where a failure
    etc.

    I tried write something but can not make it work
    select case when sum(v.qty) is not null
                and sum(v.qty) = 0 then 'Pass'
                when sum(v.qty) is not null
                and sum(v.qty) != 0 then 'Fail'
           else
             case when sum(v.qty2) is not null
               and sum(v.qty2) = 0 then 'Pass'
               else
                when sum(v.qty2) is not null 
                  and sum(v.qty2) != 0 then 'Fail'
                  end as status
              end as status
    
    
     from t3 v;
    any help is appreciated. Thank you.

    Try this,

    SELECT ID,
           CASE WHEN NVL(SUM (qty2),1) !=0 THEN 'fail'
                WHEN NVL(SUM (qty),0) != 0 THEN 'fail'
                ELSE 'pass'
           END
      FROM t3
    GROUP BY ID
    
    OUTPUT
    -------------
    
    ID RESULT
    -- ------
    A  fail
    B  fail
    C  pass
    D  fail
    Z  fail
    

    G.

  • Helps the case statement when

    I am trying to compare the (date) "LATEST_EVENT_DT" to the "Big Date" ().

    So for 'The last event,' show "CANCELLED" If the "more great Date" is superior to the "LATEST_EVENT_DT" and if not, then display the value in the column 'LATEST_EVENT_DESC'. "

    If I take the part "Last event" everything works fine. But with it in I get the error 'keyword not found FROM or planned. " If anyone can help with this?

    Select

    LATEST_EVENT_DT,


    "OIT_Closed_Date", "OIR_Closed_Date", "OIN_Closed_Date."

    largest (LATEST_EVENT_DT, nvl ('OIT_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY')), nvl ('OIR_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY')), nvl ('OIN_Closed_Date', TO_DATE ('01011950', 'MMDDYYYY'))) "Big Date"

    "Last event" =.
    CASE
    WHEN LATEST_EVENT_DT < 'Date of larger' THEN 'CANCELLED '.
    OF OTHER LATEST_EVENT_DESC
    END

    of apex01.greatest_date_vw_SGD

    Thank you

    Steven

    Hi, Steven,

    What is

    "Last event" =.

    supposed to do?  Do you want the column returned by the expression BOX to appear as the "Last event" in the output?  If so, use an alias for column after the expression, as you did with "Big Date".

    You cannot define an alias for column (such as "largest Date") and then refer to this alias in the select even where it has been set.  Derive from the column in a subquery, you can reference it in a great query, like this:

    WITH got_greatest_date AS

    (

    Select LATEST_EVENT_DT

    , "OIT_Closed_Date".

    , "OIR_Closed_Date".

    , "OIN_Closed_Date".

    largest (LATEST_EVENT_DT

    nvl ('OIT_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    nvl ('OIR_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    nvl ('OIN_Closed_Date',

    , TO_DATE ('01011950', 'MMDDYYYY')

    )

    ) AS "Big Date".

    of apex01.greatest_date_vw_SGD

    )

    SELECT eff.*

    CASE

    WHEN LATEST_EVENT_DT< "greatest="">

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as the "last event".

    OF got_greatest_date g

    ;

    You really like the names in double quotes?  Most people find them very confusing and a lot more trouble than they are worth.

  • Cannot not alias a nested CASE statement?

    isn't this possible?

    I get an error ora-00905 missing key when I try the CASE expression nested aliasing, but not the outer CASE ("test case").


    everything works fine if I leave aside the "BOLD" below:


    SOME costs,
    CASES where cost > 1100
    Then CASE when required in (10.50) then cost/2
    cost of other
    END "nested box"
    what cost > = 1100 and cost < 1500
    then cost * 1.1
    When the cost is null then 0
    cost of other
    END "test case".
    IN THE course of
    WHERE course_no in (80,20,135,450,230)
    ORDER BY cost;

    Could not see anything in the documentation on this subject, or I forgot

    Hello

    The columns may have assumed names; expressions that are just a part of computing a column cannot have alias.

    If you assign an alias, Oracle does not provide a way to reference it.

    If you need to refer to an expression, make a separate column, perhaps in a subquery.

  • Helps the case statement

    Hi Experts,

    I have a date column in the database with date, type of DATA. I want to replace a single date January 1, 1900 "to a space.

    When the case TABLE. COLUMN = January 1, 1900 'and then' ' on the other TABLE. End of column.


    When I wrote this statement... I get an error like

    Union of the incompatible types

    Please let me know where I'm missing.

    Thank you
    V

    Try this:

     
    
    CASE when TO_CHAR(TABLE.COLUMN,'dd-mon-yyyy')='01-JAN-1900'  then ' ' else TABLE .Column End
    
  • Work with the nested case statement

    Hi, I tried the SQL to the date below max but not a single runtime error

    Select the case sensitive option

    When f.rv = "BITTER" then

    (case

    When (m.SC. = 'A' and str_name = "ST_DT1")

    or (m.SC. = 'B' and str_name = "ST_DT2")

    or (m.SC. = 'C' and str_name = "ST_DT3") then

    Max (m.STDT)

    Where (mc.sc = 'C' and str_name = "ST_DT4")

    or (mc.sc = 'K' and str_name = "ST_DT5") then

    Max (MC. EDDT)

    on the other

    null

    end)

    on the other

    null

    end

    of memo_con mc

    baro_uy b

    end f

    ped pe

    where b.id = mc.id

    and pe.id = mc.mid

    and pe.id1 = 1234

    and b.cd = f.cd

    and f.id = 93;

    Could you please suggest me the correct way on it.

    Thank you

    You need a group of expression OR the only authorized linked should be aggregation function.

    Onw solution could be to put the aggregate function (MAX) education all about box.

    Like this

    SELECT max)

    case

    When f.rv = "BITTER" then

    case

    When (m.SC. = 'A' and str_name = "ST_DT1")

    or (m.SC. = 'B' and str_name = "ST_DT2")

    or (m.SC. = 'C' and str_name = "ST_DT3")

    then m.stdt

    Where (mc.sc = 'C' and str_name = "ST_DT4")

    or (mc.sc = 'K' and str_name = "ST_DT5")

    then mc.eddt

    end

    end) as maxdate

    of memo_con mc

    baro_uy b

    end f

    ped pe

    where b.id = mc.id

    and pe.id = mc.mid

    and pe.id1 = 1234

    and b.cd = f.cd

    and f.id = 93;

  • Need help on Case statement

    Hi all

    I'm stuck on the script. I question something like this

    Select HIRE_DATE,

    ENAME,

    (case when EMP_NO = 10 then

    case when there are

    (

    Select ENAME from

    EMP_DTL

    where EMP_DTL. EMP_NO = EMP_MST. EMP_NO

    ) end case

    -case when EMP_NO in (10,20,30,40) then

    case when there are

    (

    Select ENAME from

    EMP_DTL

    where EMP_DTL. EMP_NO = EMP_MST. EMP_NO)

    As TARGET_CODE)

    OF EMP_MST;

    now I'm trying return ENAME (TARGET_CODE) that I use in my case, but I get the error message. I don't know why. Please guide me.

    Concerning

    Shu

    I do not understand your query at all, so I take just a guess here:

    SQL > select m.emp_no

    2, m.hire_date

    3, m.e_name

    4, d.pl_code

    emp_mst 5 m

    left join 6

    7 (select emp_no, pl_code

    8 of emp_dtl

    9 where)

    10 (emp_no = 10 and pl_code = 'BB')

    11 or (emp_no in (20,30) and pl_code = 'LOB')

    12                      )

    13              ) d

    14 on (d.emp_no = m.emp_no)

    15;

    EMP_NO HIRE_DATE E_NAME PL_CODE

    ------ ------------ -------- ----------

    10-12 JANUARY 2013 ROB BB

    20 13 JANUARY 2013 ROBERT LOB

    30 JILL JANUARY 14, 2013

    EDIT: change the query.

  • Syntax of the case statement / WHEN

    The table I use a depreciation per fiscal year and the fiscal period.  I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year.  I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905.  I'm relatively new to sql and it is contribtuing to my problem as well.  Here is the code I have and suggestions / corrections would be appreciated.  Thanks for the help...

    SELECT

    lao PDR. DEPTID as DEPTID,

    lao PDR. ASSET_ID as ASSET_NO,

    PA. Descr as DESCRIPTION,

    lao PDR. ACCOUNT_AD as AD_ACCT,

    PDL. DE_ACCT, to take into ACCOUNT

    lao PDR. ADEATH as AMT_DEPR,

    PDL. JOURNAL_ID as JRNL_ID,

    PDL. JOURNAL_DATE as JRNL_DT,

    lao PDR. FISCAL_YEAR as FY,

    lao PDR. ACCOUNTING_PERIOD AP,

    CASE

    WHEN RDP. FISCAL_YEAR = 2014 THEN

    WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR

    END AS CURR_MONTH,

    CASE

    WHEN RDP. FISCAL_YEAR <>2014

    WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR

    END AS PRIOR_MONTH

    OF PS_DEPR_RPT pdr

    INNER JOIN PS_DIST_LN pdl

    THE pdl. BOOK = pdr. BOOK

    AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT

    AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR

    AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD

    AND pdl. ASSET_ID = pdr. ASSET_ID

    AND pdl. CF_SEQNO = pdr. CF_SEQNO

    INNER JOIN PS_ASSET PA

    WE pa. ASSET_ID = pdl. ASSET_ID

    AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT

    WHERE

    lao PDR. BUSINESS_UNIT = "A0465.

    AND pdr. BOOK = 'RUN '.

    AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))

    Hello

    2713822 wrote:

    Thank you... I appreciate the information you provide when you answer these questions.  I always try to get the amount (from the same column) for 2 rows in different columns.  I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same.  I'm only using SQL to retrieve data.  I don't have the ability to create or insert.

    I looked the information above and the CASE statement to look like this:

    CASE

    WHEN RDP. FISCAL_YEAR = 2014

    AND pdr. ACCOUNTING_PERIOD = 11

    THEN the RDP. ADEATH AS CURR_MONTH

    ON THE OTHER

    lao PDR. ADEATH AS MONTHS PREVIOUS

    END

    But I'm now getting an "ORA-00905: lack of keyword" message.

    What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10.  The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.

    Before current assets management

    01 AB01 50.01 50.03

    ....

    If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.

    'AS nome_alias' applies to the entire column.  Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.

    If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause.  for example:

    SELECT pdr.branch

    pdr.asset

    CASE

    WHEN pdr.fiscal_year = 2014

    AND pdr.accounting_period = 11

    THEN pdr.depr

    END AS curr_month

    CASE

    WHEN...

    THEN...

    END AS prior_month

    PDR

    ;

    If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.

    To find out what version of Oracle you have, use

    SELECT *.

    SINCE the release of v$.

    The output can be messy, like this:

    BANNER

    -------------------------------------------------------------------

    CON_ID

    ----------

    12 c Oracle database Release 12.1.0.1.0 - 64 bit Production

    0

    PL/SQL Release 12.1.0.1.0 - Production

    0

    CORE Production 12.1.0.1.0

    0

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    0

    NLSRTL Version 12.1.0.1.0 - Production

    0

    The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.

  • Case mix with Nested ifs statement

    Hello I need to mix a case statement with a few nested ifs, but I get an error I do not know how to start or complete the case statement. I've shortened the statement FOR readability

    Here is the code:

    < tt >

    BEGIN

    FOR events IN (SELECT EBA_CA_EVENTS. EVENT_NAME, EBA_CA_EVENTS. EVENT_ID,...)

    LOOP

    If the events. TYPE_ID <>(32230291965131516245569156552736940921) AND to_date (SYSDATE) = ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT1)

    THEN

    Dbms_output.put_line ('adjustments of the SEND E-MAIL Alert 1 "criteria);

    on the other

    If the events. TYPE_ID = (32230291965131516245569156552736940921) and nvl(events.COMPLETED_MAIL_SENT,0) <>room ')

    THEN

    Dbms_output.put_line ('SEND EMAIL FILLED WITH TERRY');

    UPDATE EBA_CA_EVENTS set COMPLETED_MAIL_SENT = piece ') where ROW_KEY = events. ROW_KEY;

    on the other

    If the events. TYPE_ID <>(32230291965131516245569156552736940921) AND to_date (SYSDATE) = ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT2)

    THEN

    Dbms_output.put_line (' fits the criteria 2nd SEND E-MAIL alert 2 "");

    on the other

    If the events. TYPE_ID <>(32230291965131516245569156552736940921) AND to_date (SYSDATE) = ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT3)

    THEN

    Dbms_output.put_line ('fits the 3rd criteria SENDING E-MAIL Alert 3 ");

    end if; -4

    end if; -3

    end if; -2

    end if; -1

    CASE

    Events WHEN. EVENT_NOT2 is null

    THEN

    If to_date (SYSDATE) > ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT1) AND nvl (events. ALERT1_SENT, 0) part <>')

    THEN

    Dbms_output.put_line ('send e-mail if day part 1');

    UPDATE EBA_CA_EVENTS set ALERT1_SENT = piece ') where ROW_KEY = events. ROW_KEY;

    end if;

    END

    other cases

    Events WHEN. EVENT_NOT2 is NOT NULL

    THEN

    If to_date (SYSDATE) > ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT1) AND nvl (events. ALERT1_SENT, 0) part <>') AND to_date (SYSDATE) < ((to_date (to_char (events. ((EVENT_DUE_DATE, "DD-MON-YYYY HH24:MI:SS"), "HH24:MI:SS MON-DD-YYYY"))-events. EVENT_NOT2)

    THEN

    Dbms_output.put_line ('If day spent game 2 with the value');

    UPDATE EBA_CA_EVENTS set ALERT1_SENT = piece ') where ROW_KEY = events. ROW_KEY;

    end if;

    END

    END LOOP;

    END

    < /tt >

    The error occurs towards the end of the case statement-case.PNG

    I also tried this the 'else' deletion before the case and a few other variations, I can't just not perfect the code however, any help would be appreciated, thanks

    BTW, I can't use IF... Logical I already tried, then once a particular branch occurs then the else statements are ignored.

    You had an extra 'END' where he shouldn't have been and were not an 'END' where TI EXPECTED have been.

    This is your modified code (I had to fill out the... that my trainer Toad worked properly)

    BEGIN
    
       FOR EVENTS IN (
                      SELECT eba_ca_events.event_name, eba_ca_events.event_id
                        FROM 
                     ) LOOP
    
          IF(
             EVENTS.type_id <> (32230291965131516245569156552736940921)
             AND
             TO_DATE(SYSDATE) = ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS') - EVENTS.event_not1))
            ) THEN
    
             DBMS_OUTPUT.PUT_LINE('Criteria fits SEND EMAIL Alert 1');
    
          ELSE
    
             IF(
                EVENTS.type_id = (32230291965131516245569156552736940921)
                AND
                NVL(EVENTS.completed_mail_sent, 0) <> ('S')
               )
                 THEN
    
                DBMS_OUTPUT.PUT_LINE('SEND COMPLETED EMAIL TO TERRY');
    
                UPDATE eba_ca_events
                   SET completed_mail_sent = ('S')
                 WHERE row_key = EVENTS.row_key;
    
             ELSE
    
                IF(
                   EVENTS.type_id <> (32230291965131516245569156552736940921)
                    AND
                    TO_DATE(SYSDATE) = ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - EVENTS.event_not2)
                  ) THEN
    
                   DBMS_OUTPUT.PUT_LINE('2nd Criteria fits SEND EMAIL Alert 2');
    
                ELSE
    
                   IF(
                      EVENTS.type_id <> (32230291965131516245569156552736940921)
                      AND
                      TO_DATE(SYSDATE) = ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - EVENTS.event_not3)
                     ) THEN
    
                      DBMS_OUTPUT.PUT_LINE('3rd Criteria fits SEND EMAIL Alert 3');
    
                   END IF; -- 4
    
                END IF; -- 3
    
             END IF; -- 2
    
          END IF; -- 1
    
          CASE
    
             WHEN EVENTS.event_not2 IS NULL THEN
    
                IF(
                   TO_DATE(SYSDATE) > ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - EVENTS.event_not1)
                   AND
                   NVL(EVENTS.alert1_sent, 0) <> ('S')
                  ) THEN
    
                   DBMS_OUTPUT.PUT_LINE(' send email if date past part 1');
    
                   UPDATE eba_ca_events
                      SET alert1_sent = ('S')
                    WHERE row_key = EVENTS.row_key;
    
                END IF;
    
             ELSE
    
                CASE
    
                   WHEN EVENTS.event_not2 IS NOT NULL THEN
    
                      IF(
                         TO_DATE(SYSDATE) > ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - EVENTS.event_not1)
                         AND
                         NVL(EVENTS.alert1_sent, 0) <> ('S')
                         AND
                         TO_DATE(SYSDATE) < ((TO_DATE(TO_CHAR(EVENTS.event_due_date, 'YYYY-MON-DD HH24:MI:SS'), 'YYYY-MON-DD HH24:MI:SS')) - EVENTS.event_not2)
                        ) THEN
    
                         DBMS_OUTPUT.PUT_LINE('if date past part 2 with value');
    
                         UPDATE eba_ca_events
                            SET alert1_sent = ('S')
                          WHERE row_key = EVENTS.row_key;
    
                      END IF;
    
                END CASE;
    
          END CASE;
    
       END LOOP;
    
    END;
    

    I hope this helps.

  • I have problem with value NULL when the use CASE statement please help this question

    I have problem with value NULL when the use CASE statement please help this question


    Table: digital_val

    SNO cl C2

    1 San1 11

    2 22 San2

    Actual result: expected to A         B

    A            B                                                                           11        22

    11 NULL

    22 NULL



    query:

    Select case when c1 = "san1" then c2,.

    case If c1 = "san2" then c2 B

    of digital_val

    I'm more curious why, when you select 2 rows, you expect a result of row?

    WITH digital_val

    AS (SELECT 1 AS 'Sno', 'San1"C1, c2 FROM DUAL 11)

    UNION ALL

    2 SELECT AS 'Sno', 'San2"C1, c2 FROM DUAL 22)

    SELECT CASE WHEN c1 is "San1" THEN END AS A c2.

    CASE WHEN c1 = "San2" THEN END AS B c2

    OF digital_val;

    With no other input, if you select 2 rows, you get 2 rows.  One of the other solutions use a max function, but is this really what you want, does not specify?

  • Help: How to use the Case statement in the ODI11g Interface?

    Hello
    My basic source I get 'Year' values and I want that these values result code in the interface and after translation want to push on the target system.
    Example:
    Database source, I get value for
    Year
    2010
    2011
    2012

    When I get the year 2010 I want to change the value in "FY10".
    When I get year 2011 I want to change the value in "FY11.
    and even for the year 2012 to "FY12.
    I've tried to make the Case statement, but had no success.
    I don't want to create the lookup table in the source system.
    Any help in this matter.

    Thank you

    Concerning
    Sher

    Published by: Sher Ullah Baig on August 26, 2012 17:52

    CASE
    WHEN source_column = '2010' THEN 'FY10.
    WHEN source_column = '2011' and THEN 'FY11.
    WHEN source_column = '2012' and THEN 'FY12.
    END

  • Help with making SQL query references to column aliases in the Case statement

    I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:


    SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,

    CASE
    WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
    WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
    WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
    WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
    WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
    WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
    WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
    WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
    WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
    WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
    END acg_elig_comm_code

    CASE
    WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
    WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
    WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
    END comm_code_description

    OF spriden, rcresar, rcrapp1

    WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')

    OR rcresar_comm_code_02 ('268 ', '269', ' 270')

    OR rcresar_comm_code_03 ('268 ', '269', ' 270')

    OR rcresar_comm_code_04 ('268 ', '269', ' 270')

    OR rcresar_comm_code_05 ('268 ', '269', ' 270')

    OR rcresar_comm_code_06 ('268 ', '269', ' 270')

    OR rcresar_comm_code_07 ('268 ', '269', ' 270')

    OR rcresar_comm_code_08 ('268 ', '269', ' 270')

    OR rcresar_comm_code_09 ('268 ', '269', ' 270')

    OR rcresar_comm_code_10 ('268 ', '269', ' 270'))


    Rcresar_aidy_code = & aidy_code

    AND rcrapp1_aidy_code = rcresar_aidy_code

    AND rcrapp1_curr_rec_ind = 'Y '.

    AND rcrapp1_seq_no = rcresar_seq_no


    AND spriden_pidm = rcresar_pidm

    AND rcrapp1_pidm = rcresar_pidm


    AND spriden_change_ind IS NULL

    ORDER BY name


    The second case statement is where I don't know exactly what it takes to get what I want.

    Output should be like:
    spriden_pidm name ID acg_elig_comm_code comm_code_description
    «0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»

    If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.

    Published by: blackhole82 on January 20, 2009 09:20

    Hello

    You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
    You can set the alias in a subquery and then use it in a great query, like this:

    WITH  sub_q  AS
    (
        SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name,
            CASE
                WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01
                WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02
                WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03
                WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04
                WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05
                WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06
                WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07
                WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08
                WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09
                WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10
            END acg_elig_comm_code   -- Originally posted with , here (error)
        FROM spriden, rcresar, rcrapp1
        WHERE (rcresar_comm_code_01 IN ('268','269','270')
                OR rcresar_comm_code_02 IN ('268','269','270')
                OR rcresar_comm_code_03 IN ('268','269','270')
                OR rcresar_comm_code_04 IN ('268','269','270')
                OR rcresar_comm_code_05 IN ('268','269','270')
                OR rcresar_comm_code_06 IN ('268','269','270')
                OR rcresar_comm_code_07 IN ('268','269','270')
                OR rcresar_comm_code_08 IN ('268','269','270')
                OR rcresar_comm_code_09 IN ('268','269','270')
                OR rcresar_comm_code_10 IN ('268','269','270'))
        AND rcresar_aidy_code = &aidy_code
        AND rcrapp1_aidy_code = rcresar_aidy_code
        AND rcrapp1_curr_rec_ind = 'Y'
        AND rcrapp1_seq_no = rcresar_seq_no
        AND spriden_pidm = rcresar_pidm
        AND rcrapp1_pidm = rcresar_pidm
        AND spriden_change_ind IS NULL
    )
    SELECT    sub_q.*,
              CASE
                  WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course'
                  WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB'
                  WHEN acg_elig_comm_code = '270' THEN 'ACG possible'
              END comm_code_description
    FROM      sub_q
    ORDER BY  name
    

    Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.

    Published by: Frank Kulash, January 20, 2009 11:35
    Syntax error has been corrected

  • Help in the CASE statement with amount

    Hello Experts

    I amw Group on

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
    With partitioning, OLAP, Data Mining and Real Application Testing options

    I'm unable to solve this Case statement.

    My requirement is that if the value of the attribute is greater than 50, then add 1 to the sum for attribute 4 the sum should be 4


    WITH T AS
    (
    Select MATH_CONV_SCR 70, 68 MATH_PERC, writ_conv_scr 66, 67 writ_per Union double all the
    Select MATH_CONV_SCR 70, MATH_PERC 48, writ_conv_scr 66, 67 writ_per Union double all the
    Select MATH_CONV_SCR 70, 68 MATH_PERC, writ_conv_scr 66, 67 double writ_per
    )
    (
    Select)
    CASE
    WHEN MATH_CONV_SCR > 50 THEN 1
    WHEN MATH_PERC > 50 THEN 1
    WHEN WRIT_CONV_SCR > 50 THEN 1
    WHEN WRIT_PER > 50 THEN 1
    TOTAL END)
    T
    )


    The expected answer is
    4
    3
    4
    for the respective folders


    Please give me the solution

    Thank you

    RB

    Hello

    Rb2000rb65 wrote:
    Hello Experts

    I amw Group on

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production...

    Thanks for posting the version and sample data; It is very useful.

    ... Select)
    CASE
    WHEN MATH_CONV_SCR > 50 THEN 1
    WHEN MATH_PERC > 50 THEN 1
    WHEN WRIT_CONV_SCR > 50 THEN 1
    WHEN WRIT_PER > 50 THEN 1
    TOTAL END)
    T

    Don't forget that the WHEN of a CASE expression clauses are mutually exclusive. If none of them are evaluated to TRUE, then all of the following are not even tried.

    )

    The expected answer is
    4
    3
    4
    for the respective folders

    Please give me the solution

    Here's one way:

    SELECT  CASE WHEN math_conv_scr > 50 THEN 1 ELSE 0 END
          + CASE WHEN math_perc      > 50 THEN 1 ELSE 0 END
          +     CASE WHEN writ_conv_scr > 50 THEN 1 ELSE 0 END
          + CASE WHEN writ_per      > 50 THEN 1 ELSE 0 END     AS total
    FROM       t;
    

Maybe you are looking for

  • PowerShell 2.0

    Is this a necessary update if I am running a home computer with no network use or remotely?  It will improve the performance of the computer at all?

  • Pavilion dv7-7080eo Wifi Win 8.1 problems

    So, I'm having a little problem with the wireless switch button on my dv7-7080eo. Although it is not officially supported by HP for the computer that is running Windows 8.1, I loaded the system top and it works pretty well outside the wireless featur

  • wasMachinAuthenticated

    Hi all, I have adivsed to use was MachinAuthenticated, but I can not even every time I have to test the results. can someone tell me how it works in detail? When I test it, sometimes the PC AD joint gets wasmachinAuthenticated is equal to true, somet

  • Best practices to make the sensitive landing page!

    HelloI do the sensitive landing page.Can someone help me with the best method for this?Thank youPOOJA

  • Problems with accordion title and content

    I hope someone can help me.  As far as I know, the coding is correct for the accordion section and content.  If you go to the order of the day & registration | Ministry of Agriculture of South Dakota and click on 'Previous years Videos', you can see