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.

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.

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

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

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

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

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

  • Using nested switch/case statements

    What is the best practice of two following switch/case statements?

    Is there an easier way (less code) to do this?

    Thank you.

    I think it's as clean as it gets:

  • call the statement box inside the case statement

    I am writing a program which requires me to run a statement box inside another case statement. Although this sounds like a simple thing, I need to be able to call the case statement using a sequence structure, where s1 sends the true value to the case, s2, a fake. Then I need to record the results of this instruction box in a text file. Attatched is a simplified version of what I'm trying to do. Please note that the way my program runs may not call the case statement without using a sequence structure, two nesting box instructions is not feasible. I hope someone out there can help me because I was stuck trying to find this for awhile.

    Thank you

    LVStudent wrote:

    [...] I can't call the case statement without using a sequence structure

    Yes you can.  You just need to be smart.

    LVStudent wrote:

    I don't think I can use a state machine to fix this.

    I think you probably can.

    With respect to your original post. What are these s1 and s2 are you talking about?  My opinion on the matter, it is that you want to select a case based on the values of several controls Boolean.  If this is correct, I do this:

    Build your Boolean controls in a table, convert the table number and insert it into the structure of your business.  No button pressed = 0, s1 = only 1, s2 = only 2 both = 3.   This works for Boolean values as much as you want and is an easy way to make a decision that depends on many entries.

  • Nested case in the Expression

    Hello

    I need to create a nested case in an expression statement, but am having no luck. Here's what I need to evaluate:

    Case ingroup.field1
    When NOT NULL then
    Case ingroup.field2
    When NULL then 'n/a '.
    Of other ingroup.field2
    end
    of other ingroup.field1
    end

    When I validate and generate and try to run the SQL outside OWB, I get the following error:
    ORA-00936: missing expression.

    Any ideas on what I could do wrong here?

    Thank you
    Paula

    Instead of using the ingroup.field1 CASE... .use

    CASE WHEN ingroup.field1 IS NOT NULL
    THEN
    CASE WHEN...

    It should work.

  • CASE statement on the 39gII

    I can't get the CASE statement to work on my 39gII.  Anyone else out there there is a bit of luck?  I keep getting syntax errors.

    It does not in the current official version of Setpbember.

  • Use the control of timing DAQmx as input in case statement

    Hello

    I'm building a VI aquire sampled under tension of a sensor in continuous mode or finished.  I was going to do this, use a box with a cable of the sample mode of the VI DAQmx calendar entry to the terminal State, the idea being that I couldn't aeither a while looping the case for continuous or simple acquisition according to the setting of this command.

    However, instead of the sample mode provided for in the case of the case statement, I just get 1 and 0.

    It's a good way to achieve this, and if so how can I get my case structure working properly?

    Thank you

    Dave

    Hi Dave,.

    Apologies - I consider that the error is from the data acquisition function? I forgot that she was using the sample entry mode.

    Perhaps, then, it will be preferable to continue using the control of the ring - cases will be numbered and will correspond to the numeric value of the selection of the ring (i.e. finite samples = 0). I have attached a small example if we know not.

    Moreover, the structure of the case cannot automatically fill for each case, in which case you can right click on the structure of the case-> add the case after.

    Best regards

  • Case statement is not spend.

    Hello

    I'm having a strange problem with a case statement.  I'm passing is a Boolean value that is set to false, but the case statement never switches to the loop of "false".  I have attached a word doc who did the screen has a step of this unique through being shot.  The photo of the top has the case highlighted with the probe #8 beside him indicate 'False. '  In the lower screen shot is the very next step that highlights the outside circle while ' loop', but the case statement is always 'True '.  Anyone seen this before?

    Gary Tyrna

    Hey Mello,

    Well, I see what you're saying and you are right, the problem is the case statement works when highlight of execution.  But I have a main case statement in the loop that either allows the state machine to execute a loop or hides them and that case is triggered for no steps to true or false.  So that was the reason why I sent the first e-mail because I could see this case change, but not the smallest.  But if this is the fix well I'll run with it and lets see case statement switch the highlight of the performance.

    Thanks again.

    Gary Tyrna

  • How can you change a menu drop-down menu in a case statement?

    Hello

    I'm trying a table find vi. This VI will be an existing xml file and once the user has selected access to its equipment, input, output and frequency it put all of these options in a string and search the XML for this exact table name and post it on one screen of output. The problem I have is my entry and exit selection must be a little different depending on the chosen equipment. I thought I could use an instruction box to change the options of selectable input and output, but I ran into snags a lot with it. For whenever I have to put a new drop of entry and exit in the drop-down menu in the case statement, he wants to put a new one in the front (I only want to enter and exit not only three I have two inputs and outputs hidden right now). I think I'm using the wrong case statement... Can someone help change my input and output, selectable options depending on the chosen equipment. Attached is my xml file, Array Find.vi (the original) and table Find_Test.vi (that's what I'm trying to change).

    Thank you

    dlovell

    Hi dlovell,

    A few changes in the attached VI:

    Requirements/possible Solutions

    • When the value of the equipment, do something
      • Add the cases to the value of equipment change event
    • Do something = decide what channels to write, to change the input and output strings
      • Read material value changed
      • Decision (case structure)
      • Channel (same method as the previous mod)

    Hope this helps

Maybe you are looking for