Query of query case Sensative

Hi all
You have a simple problem, I run a main request:

< CFQUERY name = "getprice" datasource = "adatabase" >
SELECT RTRIM (plpart) AS plpart, MIN (plunitprice) AS plunitprice
The price LIST
GROUP BY plpart
< / CFQUERY >

now to the list of price table parts are entered in lowercase it is to say that the results could look like below:

Part___Price
ABc, 10
DeF, 11
IGS, 12
JKL, 10

If I ask questions directly to the datasource there is no problem with the case being higher or lower, but when I ask query as below it returns only one result if the LIKE "#variable #" is the proper case, how can I get around this?

< CFquery dbtype = "query" name = "qoq_price" >
SELECT plunitprice
Of getprice
WHERE plpart LIKE ' #variable #
< / CFquery >

for example
If the variable was 'ABc' the QOQ returns the correct value of 10
but
If the variable was "ABC" t/t does not return a result

Problem, it's that my variables come from a table where they are at the top of the case, but in my table of prices people are entered in both cases and sometimes mixed.

Sincere friendships Guy

Thanks Peter

Completely overwhelmed my mind to simply enter the SQL code in uppercase, has been busy, trying to get an ignore case.

Everything works as a treat thank you

Tags: ColdFusion

Similar Questions

  • Problem with the input query mode. FRM 41009, 40301

    Hi all

    I have a problem with the mode of input query. What can I say, I'm in the mode of input query, and I click on a button. I get the error THAT FRM-41009 displayed.

    Now, I've wanted handled. So I created a trigger of error in order to handle the error.

    IF ERR_CODE = 41009 THEN
    NULL;
    END IF;

    A problem is that when you use the null value, it will not terminate the mode of input query, and then I get frm-40301 error.

    Second, it's that I can't use exit_form in a trigger of the error.

    I am aware that I can press F4 to exit this mode, but I don't want to do whenever I'm sure I'll get the user complaints.

    Another solution would be to put the following code in the trigger when key pressed for each button in the form:

    If: system.mode = "ENTER-QUERY" then
    exit_form;
    end if;

    But I don't want to reproduce this code in my form.

    Please can you give me an idea how to handle this correctly?

    Thank you
    Michael

    PS: Version of the form = > ORACLE FORMS 10g (Forms [32 bit] Version 10.1.2.3.0)

    I have a problem with the mode of input query. What can I say, I'm in the mode of input query, and I click on a button. I get the error THAT FRM-41009 displayed.

    What is the code in the trigger of your button When-Button-Pressed (WBP)? Maybe you should check to see if the form is in the Mode query in your WBP rather than try and remove the error? In other words, eliminate error - do not delete it. :)

    If you want instead to remove the error, there is a technique to built-ins call restricted to a trigger that does not allow them. Do this by the use of a millisecond zero Timer. For example:

    /* Sample On-Error Trigger */
    DECLARE
      n_err_cd   NUMBER := ERROR_CODE;
      t_on_error TIMER;
      ZERO  NUMBER := 0;
    BEGIN
      IF ( n_err_cd = 41009 ) THEN
        /* Create Timer to execute Exit_Form() */
        /* to Cancel Query-Mode. */
        t_timer := Create_Timer('ON_ERROR', ZERO, NO_REPEAT);
      ELSE
        /* Handle all other errors here... */
      END IF;
    END;
    
    /* Sample When-Timer-Expired Trigger */
    DECLARE
      v_Timer  VARCHAR2(30);
    BEGIN
      v_timer := Get_Application_Property(TIMER_NAME);
    
      IF ( v_timer = 'ON_ERROR' ) THEN
        /* Notice, the timer name is case sensative! */
        Exit_Form;
      END IF;
    END; 
    

    I am aware that I can press F4 to exit this mode, but I don't want to do whenever I'm sure I'll get the user complaints.

    Well, it's just standard features of Oracle Forms. If you switch the Mode request form - you must run a query or cancel the query Mode! This is how it works. Your users need to understand that and accept it - just as they accept the functional also for other programs. ;) Another option would be to add a "Cancel request" button to your form and make it so it is enabled only when the form is placed in Query Mode. Just a thought...

    I personally prefer to prevent the occurrence of an error rather than remove the error. :)
    I hope this helps.
    Craig...

  • ORA-00907

    Hello
    When executing a query, I get an error in the next part of the query


    (case
    When mas_store_item_conversion.formula = 1
    then truncate (((store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1) store_tender_comm_bid_t.mdq_value), 0)
    else (store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1)
    END)

    (case store_po_detail.other_taxes > 0, the value true, then another store_po_detail.other_taxes '-' end) as other_taxes,
    *
    ERROR on line 35:

    ORA-00907: lack of right parenthesis


    thanx

    Hello

    I doubt that the truncate function used in the case, try to replace below

    case
    when mas_store_item_conversion.formula = 1
    then (store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1)/store_tender_comm_bid_t.mdq_value
    else (store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1)
    END,
    

    Instead of

    (case
    when mas_store_item_conversion.formula = 1
    then truncate(((store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1)/store_tender_comm_bid_t.mdq_value),0)
    else (store_tender_proposal.tender_qty * mas_store_item_conversion.conversion_factor1)
    END),
    

    Thank you
    Ajay more
    http://www.moreajays.com

  • Dynamic list - is current issue

    I created a dynamic list. This works except for the IS_CURRENT parameter.
    List : dyn wizard page 11
    Template:      Wizard Progress List, Horizontal Train
    
    Query Source Type: Function Returning SQL Query
    
    Query
    
    case
    when :APP_PAGE_ID = '11' THEN
      RETURN 
      'SELECT null, progress_name label, '||
      'case WHEN NVL(:APPL_TAB_NAME,''PROJECT'')=CURRENT_TAB_NAME THEN ''Y'' else ''N'' end 
     is_current_list_entry,'||
      'null,null,id ' ||
      'FROM csrsr_req_wizard_nav '||
      'WHERE form_number_id = 3 ORDER BY 6';
    when :APP_PAGE_ID = '8' THEN
      RETURN 
      'SELECT null, current_tab_name label '||
      'FROM csrsr_req_wizard_nav '||
      'WHERE form_number_id = 1 ORDER BY 1';
    when :APP_PAGE_ID = '10' THEN
      RETURN 
      'SELECT null, current_tab_name label '||
      'FROM csrsr_req_wizard_nav '||
      'WHERE form_number_id = 2 ORDER BY 1';
    else
      RETURN 
      'SELECT null, current_tab_name label '||
      'FROM csrsr_req_wizard_nav '||
      'WHERE form_number_id = 4 ORDER BY 1';
    END CASE;
    The page I access the dynamic list is on Page 11.

    Can someone please?

    Robert
    http://apexjscss.blogspot.com

    Applications of dynamic list you generate missing a column. Your questions have 6 columns:

    SELECT
        null
      , progress_name label
      , case
          WHEN NVL(:APPL_TAB_NAME,'PROJECT') = CURRENT_TAB_NAME THEN 'YES'
          else 'NO'
        end is_current
      ,null
      ,null
      ,id
    FROM
        csrsr_req_wizard_nav
    WHERE
        form_number_id = 3
    ORDER BY
        6
    

    The examples in the list wizard have 7:

    SELECT null,
           ENAME label,
           null target,
           'YES' is_current,
           '#APP_IMAGES#del.gif' image,
           'width="20" height="20"' image_attrib,
           ENAME image_alt
    FROM  emp
    ORDER BY ename
    

    Although the target column is not used in a list of courses standard Wizard because it is not clickable, the column must always be included or the values of the column will be compensated. APEX sees your is_current as the target value column and your null image is_currentcolumn. It is advisable to include all columns and alias them:

    select
        null level
      , progress_name label
      , null target
      , case
          nvl(:appl_tab_name, 'PROJECT') = current_tab_name then 'YES'
          else 'NO'
        end is_current
      , null image
      , null image_attrib
      , null image_alt
    from
        csrsr_req_wizard_nav
    where
        form_number_id = 3
    order by
        6
    

    Also note that there are no application APPL_TAB_NAME element in this application, which will have an impact on the results of this query: nvl (: appl_tab_name, 'PROJECT') assess so always at the "PROJECT".

  • [8i] best way to replace the 'similar' value values...?

    Some examples of data:

    Sorry for the large / complex set of sample data, but there should be no need to go through it in detail =).

    2 things to keep in mind:
    (1) it is a 8i db
    (2) I can't create any tables in the db, if I can create views
    CREATE TABLE     ord_master
    (     part_nbr          CHAR(25)
    ,     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     ord_type          CHAR(2)
    ,     ord_stat          CHAR(2)
    ,     date_closed     DATE
    );
    
    -- please note, though none of the columns in ord_master are explicitly defined as NOT NULL, 
    -- none of them are NULL in the db, and given how things are input into the table, I don't 
    -- even think it's possible
    
    -- a unique order is described by ord_nbr, sub_ord_nbr.  there should only be one record in
    -- this table for a given unique combination of those columns, though they are not the p.k.
    
    -- NOTE: dates default to 12/31/1900, so in the table above, if an order is still open (thus, 
    -- not closed), it's date_closed will be 12/31/1900.  It will only change once the order closes.
    
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','1','AA','CL',TO_DATE('05/01/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','1','2','AA','CL',TO_DATE('9/14/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','2','1','AA','CL',TO_DATE('12/03/2009','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','3','1','AA','OP',TO_DATE('12/31/1900','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('ABC-123','4','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    INSERT INTO     ord_master
    VALUES     ('XYZ-123','5','1','AA','CL',TO_DATE('03/12/2004','mm/dd/yyyy'));
    
    
    CREATE TABLE     op_detail
    (     ord_nbr          CHAR(10)
    ,     sub_ord_nbr     CHAR(3)
    ,     major_seq_nbr     CHAR(4)
    ,     wctr_id          CHAR(5)
    ,     oper_stat          CHAR(2)
    ,     plan_su_rsrc     NUMBER(5,2)
    ,     plan_run_rsrc     NUMBER(11,8)
    ,     plan_subc_amt     NUMBER(15,5)
    ,     act_su_rsrc     NUMBER(5,2)
    ,     act_run_rsrc     NUMBER(7,2)
    ,     act_subc_amt     NUMBER(15,2)
    ,     act_start_dt     DATE
    ,     dt_completed     DATE
    ,     qty_planned     NUMBER(13,4)
    ,     qty_recvd          NUMBER(13,4)
    ,     qty_complete     NUMBER(13,4)
    ,     qty_scrap          NUMBER(13,4)
    ,     qty_on_hold     NUMBER(13,4)
    );
              
    -- similar to ord_master, thought none of the columns are explicitly defined as NOT NULL, 
    -- none of the records have NULL values for any of these columns, and I don't think it's 
    -- really possible with the way the system is
    
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0081', 'X516 ', 'CP', 0, 0, 0, 0, .2, 0, TO_DATE('02/03/2010', 'mm/dd/yyyy'), TO_DATE('02/03/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .87, 0, TO_DATE('04/06/2010', 'mm/dd/yyyy'), TO_DATE('04/06/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 159, TO_DATE('03/05/2010', 'mm/dd/yyyy'), TO_DATE('03/05/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '1', '0130', 'H211 ', 'CP', .5, .1, 0, .08, .63, 0, TO_DATE('02/10/2010', 'mm/dd/yyyy'), TO_DATE('02/10/2010', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0120', 'H214 ', 'CP', .3, .05, 0, 0, .68, 0, TO_DATE('05/22/2009', 'mm/dd/yyyy'), TO_DATE('05/22/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0122', 'T203 ', 'CP', 2.5, 1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0130', 'H211 ', 'CL', .5, .1, 0, .67, .3, 0, TO_DATE('05/28/2009', 'mm/dd/yyyy'), TO_DATE('05/28/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 153.12, TO_DATE('06/10/2009', 'mm/dd/yyyy'), TO_DATE('06/10/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('1', '2', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .08, 0, TO_DATE('06/17/2009', 'mm/dd/yyyy'), TO_DATE('06/17/2009', 'mm/dd/yyyy'), 3, 3, 3, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0081', 'X516 ', 'CL', 0, 0, 0, 0, 0, 0, TO_DATE('07/20/2009', 'mm/dd/yyyy'), TO_DATE('07/20/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, 3.03, 0, TO_DATE('09/11/2009', 'mm/dd/yyyy'), TO_DATE('09/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 204.16, TO_DATE('08/11/2009', 'mm/dd/yyyy'), TO_DATE('08/11/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('2', '1', '0130', 'H211 ','CP', .5, .1, 0, 1.97, 2.67, 0, TO_DATE('07/28/2009', 'mm/dd/yyyy'), TO_DATE('07/29/2009', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0170', 'X928 ', 'CP', 0, 0, 9.6, 0, 0, 255.2, TO_DATE('11/06/2009', 'mm/dd/yyyy'), TO_DATE('11/06/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0130', 'H212 ', 'CP', .5, .1, 0, .6, .03, 0, TO_DATE('10/21/2009', 'mm/dd/yyyy'), TO_DATE('10/21/2009', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0550', 'R501 ', 'WK', 1, 16, 0, 2.2, 12.4, 0, TO_DATE('05/19/2010', 'mm/dd/yyyy'), TO_DATE('12/31/1900', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('3', '1', '0324', 'Y000 ', 'CL', .1, .2, 0, 0, .07, 0, TO_DATE('02/04/2010', 'mm/dd/yyyy'), TO_DATE('02/04/2010', 'mm/dd/yyyy'), 5, 5, 5, 0, 0);
    INSERT INTO     op_detail
    VALUES     ('4', '1', '0324', 'Y000 ', 'CP', .1, .2, 0, 0, .59, 0, TO_DATE('02/06/2004', 'mm/dd/yyyy'), TO_DATE('02/06/2004', 'mm/dd/yyyy'), 4, 4, 4, 0, 0);
    This is the query, I'm working with right now:
    SELECT     o.part_nbr               
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
    ,          AVG(s.plan_su_rsrc)          AS avg_plan_setup
    ,          MAX(s.plan_su_rsrc)          AS max_plan_setup
    ,          STDDEV(s.plan_su_rsrc)     AS sdev_plan_setup
    ,          MIN(s.plan_run_rsrc)     AS min_plan_run
    ,          AVG(s.plan_run_rsrc)     AS avg_plan_run
    ,          MAX(s.plan_run_rsrc)     AS max_plan_run
    ,          STDDEV(s.plan_run_rsrc)     AS sdev_plan_run
    ,          MIN(s.plan_subc_amt)     AS min_plan_subc
    ,          AVG(s.plan_subc_amt)     AS avg_plan_subc
    ,          MAX(s.plan_subc_amt)     AS max_plan_subc
    ,          STDDEV(s.plan_subc_amt)     AS sdev_plan_subc
    ,          MIN(s.act_su_rsrc)          AS min_act_setup
    ,          AVG(s.act_su_rsrc)          AS avg_act_setup
    ,          MAX(s.act_su_rsrc)          AS max_act_setup
    ,          STDDEV(s.act_su_rsrc)     AS sdev_act_setup
    ,          MIN(s.act_run_rsrc)          AS min_act_run
    ,          AVG(s.act_run_rsrc)          AS avg_act_run
    ,          MAX(s.act_run_rsrc)          AS max_act_run
    ,          STDDEV(s.act_run_rsrc)     AS sdev_act_run
    ,          MIN(s.act_subc_amt)          AS min_act_subc
    ,          AVG(s.act_subc_amt)          AS avg_act_subc
    ,          MAX(s.act_subc_amt)          AS max_act_subc
    ,          STDDEV(s.act_subc_amt)     AS sdev_act_subc     
    ,          MIN(s.act_start_dt)          AS min_start
    ,          MAX(s.act_start_dt)          AS max_start
    ,          MIN(s.dt_completed)          AS min_comp
    ,          MAX(s.dt_completed)          AS max_comp
    ,          MIN(s.qty_planned)          AS min_qty_plan
    ,          AVG(s.qty_planned)          AS avg_qty_plan
    ,          MAX(s.qty_planned)          AS max_qty_plan
    ,          STDDEV(s.qty_planned)     AS sdev_qty_plan
    ,          MIN(s.qty_recvd)          AS min_qty_recvd
    ,          AVG(s.qty_recvd)          AS avg_qty_recvd
    ,          MAX(s.qty_recvd)          AS max_qty_recvd
    ,          STDDEV(s.qty_recvd)          AS sdev_qty_recvd
    ,          MIN(s.qty_complete)          AS min_qty_comp
    ,          AVG(s.qty_complete)          AS avg_qty_comp
    ,          MAX(s.qty_complete)          AS max_qty_comp
    ,          STDDEV(s.qty_complete)     AS sdev_qty_comp
    ,          MIN(s.qty_scrap)          AS min_qty_scrap
    ,          AVG(s.qty_scrap)          AS avg_qty_scrap
    ,          MAX(s.qty_scrap)          AS max_qty_scrap
    ,          STDDEV(s.qty_scrap)          AS sdev_qty_scrap
    ,          MIN(s.qty_on_hold)          AS min_qty_hold
    ,          AVG(s.qty_on_hold)          AS avg_qty_hold
    ,          MAX(s.qty_on_hold)          AS max_qty_hold
    ,          STDDEV(s.qty_on_hold)     AS sdev_qty_hold
    ,          COUNT(*)                    AS rec_cnt
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          (     -- begin in-line view a, to get the min act_start_dt for each order
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ) a     -- end in-line view a          
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbr
    It gives me a lot of descriptive statistics on data stored in the database, divided into groups of the time period.

    I have 7 sets of possible values for the wctr_id column, which are groups of similar/identical positions and should be treated as the same, assuming that the ord_nbr, sub_ord_nbr and major_seq_nbr are the same. In my case statement example above, every time I find 'H211' or 'H212', I'm replacing it with "Z211', which is my new unique identifier for all wctr in the Group ("H211', "H212"). I have 7 of these kinds of groups that should be replaced by a new unique identifier. Is my statement CASE (above) the best way to do it, or is there a better way? These groups of similar-wctr_id are not listed in a table anywhere.

    Hello

    As always, thanks for posting the CREATE TABLE and INSERT statements. It is very useful and leads to the more quickly, better solutions.
    Another thing that is useful and promotes better solutions, faster, is to simplify your problem.
    For example, you need to calculate a large number of aggregates, but looks like you already know how to do this. This issue only affects the CASE expressions, and how they interact with the GROUP BY clause. So just cut most of the aggregate functions.
    Also, it seems that the finer points of view one online have nothing to do with your current problem. For purposes of recognition of this problem, pretend that one is a regular display, so it does not clutter the main request.

    I think your problem might be reformulated as follows:
    You already have a query like this:

    CREATE OR REPLACE VIEW a
    AS
              SELECT     s1.ord_nbr
              ,          s1.sub_ord_nbr
              ,          MIN     (
                             CASE
                                  WHEN     s1.act_start_dt     > TO_DATE('01/01/2000','mm/dd/yyyy')
                                  THEN     s1.act_start_dt
                             END
                             )          AS ord_min_start
              FROM          op_detail s1
              GROUP BY     s1.ord_nbr
              ,          s1.sub_ord_nbr
    ;
    
    SELECT     o.part_nbr
    ,          s.major_seq_nbr          AS op_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END                         AS wctr
    ,          MIN(s.plan_su_rsrc)          AS min_plan_setup
              -- lots of other agtgregates go here in real query
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END                         AS time_period
    FROM          ord_master o
    ,          op_detail     s
    ,          a          -- in real query, a is an in-line view
    WHERE     o.ord_nbr          = s.ord_nbr
    AND          o.sub_ord_nbr     = s.sub_ord_nbr
    AND          o.ord_nbr          = a.ord_nbr
    AND          o.sub_ord_nbr     = a.sub_ord_nbr
    AND          o.ord_type     = 'AA'
    AND          o.ord_stat     IN ('CL','OP')
    AND          s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          CASE          -- CASE statement to replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                   WHEN     s.wctr_id     IN ('H211','H212')
                   THEN     'Z211'
                   ELSE     s.wctr_id
              END
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ORDER BY     o.part_nbr
    ,          CASE
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                   THEN     '12 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                   THEN     '24 mos. back'
                   WHEN a.ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                   THEN     '36 mos. back'
                   ELSE '37 mos. back +'
              END
    ,          s.major_seq_nbr
    ;
    

    which produces this output:

    `                       MIN_
                           PLAN_
    PART_NBR   OP_N WCTR   SETUP TIME_PERIOD
    ---------- ---- ----- ------ --------------
    ABC-123    0081 X516      .0 12 mos. back
    ABC-123    0130 Z211      .5 12 mos. back
    ABC-123    0170 X928      .0 12 mos. back
    ABC-123    0324 Y000      .1 12 mos. back
    ABC-123    0120 H214      .3 24 mos. back
    ABC-123    0122 T203     2.5 24 mos. back
    ABC-123    0130 Z211      .5 24 mos. back
    ABC-123    0170 X928      .0 24 mos. back
    ABC-123    0324 Y000      .1 24 mos. back
    ABC-123    0324 Y000      .1 37 mos. back +
    

    The output is correct; the problem is, can we get the same results without 2 copies of the expression BOX wctr and 3 copies of the expression BOX time_period?
    What is a good description of the problem?

    To start, you can use aliases for columns in the ORDER BY clause. Unfortunately, it's the only place where you can use column aliases in the same query, where they are defined . You can calculate them in a query-sib and then use them in queries Super.
    In other words, wouldn't be nice if we had a table just like op_detail, but with an extra column called wctr? Make a view: either a regular view (especially if wctr, calculated in the same way, to be used for several different queries) or view online, as shown below.
    Wouldn't be great if there was a table that was like a, except that he had calculated alreay time_period? Make a view: either a regular view, or a view online, as shown below.

    SELECT     o.part_nbr
    ,     s.major_seq_nbr          AS op_nbr
    ,     s.wctr
    ,     MIN(s.plan_su_rsrc)          AS min_plan_setup
         -- lots of other agtgregates go here in real query
    ,     a2.time_period
    FROM     ord_master      o
    ,     (          -- Begin in-line view s, with data from op_detail
                 SELECT  op_detail.*      -- or list all columns needed in main query
              ,     CASE          -- replace similar-to wctr_id's with a single new wctr_id, so we can treat them as the same
                       WHEN     wctr_id        IN ('H211','H212')
                       THEN     'Z211'
                       ELSE     wctr_id
                   END                    AS wctr
              FROM     op_detail
         ) s          -- End in-line view s, with data from op_detail
    ,     (           -- Begin in-line view a2, to compute time_period
              SELECT  a.*
              ,     CASE
                       WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-12)
                           THEN     '12 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-24)
                           THEN     '24 mos. back'
                           WHEN ord_min_start     >     ADD_MONTHS(SYSDATE,-36)
                           THEN     '36 mos. back'
                           ELSE '37 mos. back +'
                   END                         AS time_period
              FROM     a          -- in real query, a is an in-line view
         ) a2          -- End in-line view a2, to compute time_period
    WHERE     o.ord_nbr     = s.ord_nbr
    AND     o.sub_ord_nbr     = s.sub_ord_nbr
    AND     o.ord_nbr     = a2.ord_nbr
    AND     o.sub_ord_nbr     = a2.sub_ord_nbr
    AND     o.ord_type     = 'AA'
    AND     o.ord_stat     IN ('CL','OP')
    AND     s.oper_stat     IN ('CL','CP')
    GROUP BY     o.part_nbr
    ,          s.major_seq_nbr
    ,          s.wctr
    ,          a2.time_period
    ORDER BY     o.part_nbr
    ,          a2.time_period
    ,          s.major_seq_nbr
    ;
    

    In your example, wctr is identical to wctr_id, except for two values. If it was more complicated (for example, if there is not only 2 values that must be mapped on 'Z211', but also 3 to did not amount to "Z987", and 1 which should be treated as "A012" and 5 who should appear as "A666" and...), then you pourriez encode this in an expression BOX humongeous (one nested expression BOX if it involves more than 128 branches) , but it actually belongs to a table, where you have the gross wctr_id (such as "H211") in a column and its equivalent correspondent (for example "Z211") in another. I know that you said that you cannot create new tables; I'm just pointing out that then you can tell people that won't let you create tables, it's a bad idea, likely to lead to errors and some time in the future.

  • How to check automatically check box a specific word is entered in a text field?

    I need help for a formula; I want to enter a specific word in a text field (labeled: food Group1).

    If I type the word 'Fruit', I want a check box (labeled: Fruit1) which appears later in my form to fill out.

    If I type the word "Grain", I want a box (marked: Grain1) which appears later in my form to fill out.

    Can someone please help me with a script that I can insert?

    Thank you very much!

    Kind regards

    Novice

    > I want to use capital LETTERS when you fill out the form

    Text comparisons are always case sensative.

    > Well, I need to all food includes Fruits, vegetables, cereals, meat, dairy products.

    > Appear which means, that when I type of fruit or grain in the text field, a check will "appear" in the box no fields are hidden or created. (not sure what you're asking here)

    On the forms fields can be visible or hidden. Appear implies that they are not visible or do not exist.

    > No, just a Word as one box of targets. for example, if I type "FRUIT" in the text field (labeled: Food Group), which should place a check in the box (labeled: Fruit1).

    If you have a limited number of registrations and specific words in a specific foramt, I would use a drop down box.

    I would like to use the 'Blur' action with the followting custom JavaScript:

    Fruits, vegetables, cereals, meat, dairy products.
    this.resetForm (["Fruit1", "Grain1", "Vegetable1", "Meat1", "Dairy1"]);  clear the result fields.

    test the text entered;
    var oCheckBox = null;
    Switch (Event.value)
    {
    case "FRUIT":
    oCheckBox = this.getField ("Fruit1");
    break;
    case "GRAIN":
    oCheckBox = this.getField ("Grain1");
    break;
    case "VEGETABLES":
    oCheckBox = this.getField ("Vegetable1");
    break;
    case 'MEAT ':
    oCheckBox = this.getField ("Meat1");
    break;
    case 'MILKMAN ':
    oCheckBox = this.getField ("Dairy1");
    break;
    by default:
    App.Alert ("No match for------" "+ event.value +"------"!", 1, 0);
    break;
    } / / end of switch.
    If (oCheckBox! = null)
    {
    oCheckBox.checkThisBox(0,true);
    }

  • Insufficient privileges. "Access home page. Error details Error Codes: C64RS3Z2

    Hello Expert;

    I am trying to deploy a catalogue (created in OBIEE 11.1.1.6.0) on my instance (OBIEE 11.1.1.7.0), when I try to load the analytical page I get the following error

    "No sufficient privileges." Access home page. "Details of the error, the Error Codes: C64RS3Z2"

    I try to check for roles as described in another thread and confirmed that the user weblogic has the catalog has the BIAdministrators role, consumer of BI, BI author role authenticated role.

    Please notify.

    Thank you

    Bahija

    Hello

    I have this problem happens because of the lower version of the catalog. To my catalog u just open the catalog on OBIEE 11.1.1.7 Offin mode. It will automatically upgrate catalog version obiee 11.1.1.7 then migrate this catalog using EM.

    If you have a problem with

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27005] Unresolved column: "Transactions". "' Transaction ID to Arrangement. (HY000)

    Then, you will need to check the RPD. Open the RPD in online mode & check if ".» Column Arrangement transaction ID"is present in the table of"Transactions"or not.

    Here the names of columns & table name should be same (case sensative) as: "Transactions". "' Transaction ID to Arrangement.

  • Take the attributes advance case-insensitive in af:query research?

    Hello

    I use JDeveloper 11.1.2.4

    I have an af:query on my screen. My main VO has many attributes but the af VIewCriteria: query is empty.

    Since it is empty, then there is no fields on the af: query. I goto the advanced option and a field. Research on the attribute that I added watch case-insensitive behavior.

    Is it possible that I can do the field added by advanced search case insensitive results.

    Note: I HAVE AN EMPTINESS of the CRITERIA overview

    Thank you

    You can probably not override buildViewCriteriaClauses() in the class ViewObjectImpl, then use something like viewCriteria.setUpperColumns (true)

    Dario

  • eHref and a Case statement in Sql query

    Hi all

    I have a select statement that looks like this:

    Select

    case when dbms_desc = 'ORACLE' and then ' < a href = "f? p = & APP_ID.:115: & SESSION. : & DEBUG. : & PAGE. : 53 "> #DATABASE_NAME # < /a > '

    When dbms_desc = "SQL SERVER" and then "< a href =" f? p = & APP_ID.:115: & SESSION. : & DEBUG. : & PAGE. : 59 "> #DATABASE_NAME # < /a > '"

    Another null

    end as database_name,

    Decode(databases.inactive_flag,'Y','Yes','N','No',null) inactive_flag, servername,.

    application name, decode(application.critical_flag,'Y','Yes','N','No',null) critical_flag,

    Decode(application.inactive_flag,'Y','Yes','N','No',null) app_inactive_flag, databases.database_id

    application, database, server, application_database_int

    where databases.database_id = application_database_int.database_id (+) and

    application_database_int.application_id = application.application_id (+) and

    databases.server_id = server.server_id and: P54_DBMS_DESC = dbms_desc and

    (upper (database_name) like '%' | upper(:P54_DATABASE_NAME) |) '%')

    order by database_name

    This query creates a report of classis. The result is the following:

    I wanted to see was the name of the database in the first column in the form of links. What is the problem with the query?

    INKA says:

    I use Apex v5 and I don't see where I can put the attributes column for the column database_name "display under" for "Standard report column.

    In the designer of the Page, select the report column in the browser on the left pane and change the properties in the property editor on the right, the column definition Type plain text and special escape characters No. See the Release Notes for the naming of the differences column property in the APEX 5.0.

  • Need to print the results of a query in a CASE statement

    I want to print the results of a query in a CASE statement:

    SELECT RUN_STATUS

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where START_TS >

    (sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e

    The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.

    If I execute this statement, it throws an error stating:

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: 1 column: 96

    How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.

    Thanks in advance!

    Hey guys,.

    I found the solution:

    SELECT

    RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0

    THEN "NO JOB RAN.

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where

    START_TS > (select sysdate - XXAFL_MINUTES MINUTE))

    where

    RUN_STATUS is not null;

    The output:

    NO JOBS RAN AFTER 09:07:54

    Thanks to you all!

  • give if or for cases of xml query condition

    Hi all

    I have the query to generate xml below.

    I would like to add in weather conditions that's if or case.

    Suppose I want to give in employee tag provided

    If e.comm is not null and e.sal > 1000 then this tag set complete should not display other wise.

    for example:

    This tag a commission and salary is greater than 1000 so this will show other wise tag of < employee > full will not be displayed.

    < employee >

    < > 7839 EMPNO < / EMPNO >

    KING of < ENAME > < / ENAME >

    < SAL > 1300 < / SAL >

    < COMM > 100 < / COMM >

    < / employee >

    (SELECT XMLELEMENT

    "Ministry."

    XMLFOREST)

    d.DEPTNO AS "Deptno."

    (SELECT XMLAGG (XMLELEMENT)

    "Employee."

    XMLFOREST (e.empno,

    e.Ename,

    e.job,

    e.Mgr,

    e.HireDate,

    e.SAL,

    e.comm)

    ))

    FROM emp e

    WHERE e.deptno = d.deptno) "EmployeeList".

    )

    ). EXTRACT ("*") AS "departments".

    D DEPT

    WHERE d.deptno = 10;

    Please review.

    Use a CASE, nothing special to XML here statement:

    (SELECT XMLELEMENT

    "Ministry."

    XMLFOREST)

    d.DEPTNO AS "Deptno."

    (SELECT XMLAGG)

    -CASE WHEN e.comm is not null and e.sal > 1000 THEN

    XMLELEMENT)

    "Employee."

    XMLFOREST (e.empno,

    e.Ename,

    e.job,

    e.Mgr,

    e.HireDate,

    e.SAL,

    e.comm)

    )

    END

    )

    FROM emp e

    WHERE e.deptno = d.deptno) "EmployeeList".

    )

    ). EXTRACT ("*") AS "departments".

    D DEPT

    WHERE d.deptno = 10;

  • How to filter data according to internal application and in case if returns nothing outside the query must return all the lines

    create table ab (a number, b varchar2 (20));

    Insert into ab

    Select rownum, rownum. "" sample "

    of the double

    connect by level < = 10

    create table bc (a number, b varchar2 (20));

    Insert into BC.

    Select rownum + 1, rownum + 1 | "" sample "

    of the double

    connect by level < = 10

    Select * AB

    where b in (select b BC where b = "2sample")

    This query will return me 1 row, but there are cases where the value of the parameter b is null

    and that it should return all rows in the table

    as

    Select * AB

    where b in (select b BC where b = "2sample")

    which return specific values, but I want to change in a way when the inner query returns nothing then outer query should return all the lines and works as

    Select * AB;

    Is it possible to put in a single query

    Hello

    You seem to ask for different things.  You want all the lines AB when

    1. The parameter ("2sample' in the example) is NULL, or when
    2. There is no corresponding row in the 2 tables (which could happen even if the parameter is not NULL)

    ?

    Assuming you want the option 2, here's one way:

    WITH got_rnk AS

    (

    SELECT ab.*

    DENSE_RANK () (ORDER IN CASE

    WHEN b (IN)

    SELECT b

    BC.

    WHERE b = "2sample" - parameter

    )

    THEN "A".

    OF ANOTHER 'B '.

    END

    ) AS rnk

    AB

    )

    SELECT a, b

    OF got_rnk

    WHERE rnk = 1

    ;

    This does not assume b is unique in each table.

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.

  • Case statement in the SQL Query prompt dashboard

    Hi Experts,

    I use the following case statement to generate default values in the prompt dashboard based on a condition (the other guest-generated values). Below are two of the query I've tried and the syntax error. I tried all the possibilities (like giving apostrophes, double quotes, don't quote not etc.), but could not understand the question. Don't know what exactly I'm missing here.

    Query 1:

    SELECT

    CASE

    WHEN @{PRType} = monthly THEN 'Participant pay '. "" Amount of PayRate "="15000"

    WHEN @{PRType} = daily THEN 'Participant pay '. "" Amount of PayRate "="650"

    WHEN @{PRType} = hourly THEN 'Participant pay '. "" Amount of PayRate "="1"

    ELSE ' 0'

    END

    OF 'PA-Participant pay. '

    Query 2:

    SELECT

    CASE

    WHEN @{PRType} = monthly THEN "15000"

    WHEN @{PRType} = daily THEN "650"

    @{PRType} = schedule THEN '1'

    ELSE ' 0'

    END

    OF 'PA-Participant pay. '

    This is the query that is generated in the log with error message file.

    1 log message:


    SELECT CASE WHEN Hourly = Monthly THEN "Participant Payroll"."Payrate Amount" = '15000' WHEN Hourly = Daily THEN "Participant Payroll"."Payrate Amount" = '650' WHEN Hourly = Hourly THEN "Participant Payroll"."Payrate Amount" = '1' ELSE '0' END FROM "PA-Participant Payroll"

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>=: Syntax error [nQSError: 26012]. (HY000)



    Comment 2:

    ;CASE WHEN To_Char (Hourly) = 'Hourly' THEN 1 ELSE 0 END 

    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error occurred. [nQSError: 43113] The message returned by OBIS. [nQSError: 27002] Near <>(): syntax error [nQSError: 26012]. (HY000)

    Sorry, I wasn't clear... you must always put this CASE statement in a valid SQL SELECT statement.

    SELECT

    CASE

    When ' @{PRType}' = 'Monthly' THEN '15000'

    When ' @{PRType}' = 'Daily' THEN '650'

    ELSE '0' END

    OF 'PA-Participant pay. '

  • Oracle query sort by case-sensitivity

    Hi all

    I use the oracle 11g database.

    My use case is that I have a table with the following values

    Name table - test

    product id     productsortdescription
    H58098        ACETAMIDOHYDROXYPHENYLTHIAZOLE
    043994         Alloy .MM.INTHICK
    

    My query is

    select * from test order by productsortdescription;
    

    This query gives the result as it is like

    product id productsortdescription

    H58098 ACETA

    product id productsortdescription

    H58098 ACETA

    produit id productsortdescription

    H58098 ACETA

    product id     productsortdescription

    H58098        ACETA

    product id     productsortdescription
    H58098        ACETAMIDOHYDROXYPHENYLTHIAZOLE
    043994         Alloy .MM.INTHICK
    

    MIDOHYDROXYPHENYLTHIAZOLE

    043994 alloy. MR. INTHICK

    but early output/outcome should be as below:

    product id productsortdescription

    043994Alloy. MR. INTHICK

    H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE

    like all and ACE in productsortdescription

    l is in a small suitcase to C.

    The NLS Session parameters are as follows

    SELECT * from NLS_SESSION_PARAMETERS;

    NLS_LANGUAGE AMERICAN

    NLS_TERRITORY AMERICA

    NLS_CURRENCY $

    NLS_ISO_CURRENCY AMERICA

    NLS_NUMERIC_CHARACTERS.,.

    NLS_CALENDAR GREGORIAN

    NLS_DATE_FORMAT DD-MON-RR

    NLS_DATE_LANGUAGE AMERICAN

    NLS_SORT BINARY

    NLS_TIME_FORMAT HH.MI. SSXFF AM

    NLS_TIMESTAMP_FORMAT-DD-MON-RR HH.MI. SSXFF AM

    NLS_TIME_TZ_FORMAT HH.MI. SSXFF AM TZR

    NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI. SSXFF AM TZR

    NLS_DUAL_CURRENCY $

    BINARY NLS_COMP

    NLS_LENGTH_SEMANTICS BYTES

    NLS_NCHAR_CONV_EXCP FAKE

    Please, help me in this scenario.

    One option is to use the NLSSORT function. Most of the ASCII character set defines the sort lowercase before uppercase but EBCDIC kinds of lowercase before uppercase. So you can use

    with t as)

    Select the id "H58098", "ACETAMIDOHYDROXYPHENYLTHIAZOLE" union str double all the

    SELECT id, ' 043994 ',' alloy. Mr. INTHICK' double str

    )

    SELECT id, str

    t

    NLSSORT order (str, 'NLS_SORT = EBCDIC')
    ;

    ID STR

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

    043994 alloy. MR. INTHICK

    H58098 ACETAMIDOHYDROXYPHENYLTHIAZOLE

    Of course, if your strings can contain non-alphanumeric characters, you should check that the sort of EBCDIC order is acceptable for them as well. To check this, you can use something like

    with t (str, ascii) as long as)

    Select chr(level+32), level + 32 double connect by level<=>

    )

    Select str, ascii from t by NLSSORT (str, 'NLS_SORT = EBCDIC')

    ;

    or simply do a search of the internet on EBCDIC. You can also substitute other kinds of language for EBCDIC and see if any of them meet your needs. See Appendix A of the Guide to support globalization for the list of valid values for NLS_SORT.

    You say that you are on 11g - if you want to say 11.2.x, then you can use the listagg function to get a more compact view of the sort order:

    with t (str, ascii) as long as)

    Select chr(level+32), level + 32 double connect by level<=>

    )

    Select listagg (str) in the Group (order by NLSSORT (str, 'NLS_SORT = EBCDIC')) as EBCDIC_order

    t

    ;

    EBCDIC_order


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

    . <(+|&!$*);- %_="">?': #@'="abcdefghijklmnopqr~stuvwxyz[^]{ABCDEFGHI}JKLMNOPQR\STUVWXYZ0123456789

    Kind regards

    Bob

  • CASE... Instruction WHEN... Query does not

    Hello
    Can someone help me fix the following code:
    select * from(
    select col1,col2,
    CASE 
     WHEN 
     Percentage >=75 THEN 'red'
     ELSE
     'green'
     end as color from (select
     ROUND(((COUNT(CASE WHEN class ='A' THEN 1 END)/ 
    nullif((SUM(CASE WHEN class ='B' THEN 1 END)+ SUM(CASE WHEN class ='C' THEN 1 END)),0))*100),1)) as Percentage, col4,col5
    from table
    group by class,col2 
    order by class;
    P.S: Percentage corresponds to the alias for complex queries, I use... This isn't the name of the column.
    Front end is APEX, once the code is syntactically correct, that I can use in the APEX. So don't report it in the forum of the APEX.

    Hello

    You cannot set a column alias (for example, percentage) and referencing this alais in the same SELECT clause.
    What you can do is to set the aliases in a subquery (such as got_aggregates, below), then use that alias anywhere you want in a super-requete:

    WITH     got_aggregates     AS
    (
         SELECT       region, country, site
         ,       COUNT (CASE WHEN group_closed           = 'A' THEN 1   END)     AS closed_by_a
         ,       COUNT (CASE WHEN group_closed           = 'B' THEN 1   END)     AS closed_by_b
         ,       COUNT (*)                                                      AS total
         ,       COUNT (CASE WHEN group_first_responded = 'B' THEN 1   END)     AS first_responded_by_b
         ,       AVG   (CASE WHEN group_first_responded = 'B' THEN 100
                                                             ELSE 0   END)     AS percentage
         ,       AVG   (CASE WHEN group_closed           = 'A' THEN 100
                                                             ELSE 0   END)     AS closed_by_a_total
         FROM       statistics
         WHERE       group_closed     IN ('A', 'B')
         GROUP BY  region, country, site
    )
    SELECT       a.*
    ,       100 * closed_by_b
               / NULLIF ( first_responded_by_b
                       , 0
                     )     AS closed_by_b_1st_resp_by_b
    ,       CASE
               WHEN  percentage  >= 50  THEN  'RED'
                                         ELSE  'GREEN'
           END                  AS color
    FROM       got_aggregates  a
    ORDER BY  region, country, site
    ;
    

    You will notice that I used alaises defined in got_aggregates not only for the color, but also for the closed_by_b_1st_resp_by_b.
    Output of your sample data:

    `                                                                  CLOSED
                                                                        _BY_B
                                               FIRST_          CLOSED   _1ST_
                        CLOSED CLOSED       RESPONDED  PERCENT  _BY_A RESPOND
    REGION COUNTRY SITE  _BY_A  _BY_B TOTAL     _BY_B      AGE _TOTAL   _BY_B COLOR
    ------ ------- ---- ------ ------ ----- --------- -------- ------ ------- -----
    Asia   China   Park      2      1     3         2     66.7     67      50 RED
    Asia   India   Shop      1      2     3         1     33.3     33     200 GREEN
    Europe France  Park      2      1     3         2     66.7     67      50 RED
    Europe France  Shop      1      2     3         1     33.3     33     200 GREEN
    Europe Switzer Park      2      2     4         1     25.0     50     200 GREEN
           land
    

    I changed the GREEN/RED 75 to 50 threshold, just so that we would see different colors when using these sample data.

    Formatting numbers are better done by your front end. I used SQL * more commands such as

    COLUMN     percentage               FORMAT     99999.9          HEADING     PERCENT|AGE
    

    to get the above result. You can use ROUND or TO_CHAR in the query itself if you prefer to do it like that.

Maybe you are looking for