using case when statement or decode unfavorable in where clause

Hi the gems...

I have a problem in the following query...
I try to use when case statement in where clause of a select query.


Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when ' > ' = ' > ' then ' cr.salary > 5000')
When ' > ' = ' < ' then ' cr.salary < 5000'
When ' > ' = '=' and then 'cr.salary = 5000'
Another null
(end);


the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
That is why, for the execution of the query, I put ' > ' in this place.

If the original query will look like this (for reference):

Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
CR. Salary salary
of customer_details cr
where (case when variable = ' > ' then ' cr.salary > 5000')
When the variable = ' < ' then ' cr.salary < 5000'
When the variable = '=' and then 'cr.salary = 5000'
Another null
(end);


so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
If the user selects '=', then the filter will be 'where cr.salary = 5000 '.

but I get the error "ORA 00920:invalid relational operator.

Help, please... Thanks in advance...

Hello

select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
       cr.salary                                      as salary
 from customer_details cr
where (    v_variable = 'bigger'
       and cr.salary > 5000
      )
   or (    v_variable = 'less'
      and cr.salary < 5000
       )
   or (    v_variable = 'eq'
        and cr.salary = 5000
       )

Published by: user6806750 on 22.12.2011 14:56
For some reason that I can't write in sql "<', '="">", "=".

Tags: Database

Similar Questions

  • doubt in the case when statement

    Hi the gems...

    I have a case when statement in a select clause... ago total three conditions in the case when statemnt.

    now my question is if all theconditions gets mapped, what happens?

    is only the first condition is executed and rest two is ignored or the third condition will overwrite the previous two?

    Please help... Thanks in advance...

    You can see it with:

    select case when 1=1 then 1
                when 2=2 then 2
                when 3=3 then 3
           end test
    from dual;
    
    TEST
    ---------
    1
    

    You get only the first result!

    Published by: hm on 18.11.2011 04:11

  • DECODE inside the WHERE clause

    Hi all:

    I can't get the DECODE statement to work inside my WHERE clause. I have read the information on
    Tahiti.Oracle.com
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions049.htm#i1017437

    But still can not get it to work. Initially, I had he works as dynamic SQL and then run that string, but I am not allowed to use dynamic SQL statements and to do 'Real' PL/SQL.

    I have the following WHERE clause (more info after the WHERE clause)
    WHERE 
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no 
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no 
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no 
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~')) 
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~')) 
         AND te.comp_id = p_CompID 
         AND te.site_id = p_SiteID 
         AND INSTR('' || p_TaskType || '', te.task_type) > 0 
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1)) 
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1)) 
         || whereClauseStatus 
         || whereClauseFromDate 
         || whereClauseToDate;
    As you can see, initially I was adding values of "whereClauseStatus, whereClauseFromDate, whereClauseToDate" and it has been defined with the following PL/SQL code:
         IF(p_TaskStatus = 'C') THEN
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.act_end_date) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.act_end_date) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         ELSE
              -------------------------------------------------------------------------------------------
              --     Incomplete and All statuses are filtered on the currdate
              -------------------------------------------------------------------------------------------
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.currdate) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.currdate) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         END IF;
         
    
         IF (p_TaskStatus = 'I') THEN
              whereClauseStatus := ' AND act_end_date IS NULL ';
         ELSIF (p_TaskStatus = 'C') THEN
              whereClauseStatus := ' AND act_end_date IS NOT NULL ';
         ELSE
              whereClauseStatus := '';
         END IF;
    I have serious problems getting the DECODE statement to replace the three variables in the annex.

    Any help would be greatly appreciated.

    Thank you
    Andy

    Published by: BluShadow on August 2, 2011 15:11
    addition of {noformat}
    {noformat} tags for clarity. Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    I'll take a wild shot in the dark, and suggests that it is perhaps what you are looking for...

    WHERE
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~'))
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~'))
         AND te.comp_id = p_CompID
         AND te.site_id = p_SiteID
         AND INSTR('' || p_TaskType || '', te.task_type) > 0
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1))
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1))
         AND TRUNC(te.act_end_date) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.act_end_date))
            AND TRUNC(te.act_end_date) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(tw.act_end_date))
            AND TRUNC(te.currdate) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
         AND TRUNC(te.currdate) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
            AND (  (act_end_date IS NULL AND p_TaskStatus = 'I')
                OR (act_end_date IS NOT NULL AND p_TaskStatus = 'C')
                OR p_TaskStatus NOT IN ('I','C')
                )
    

    Published by: BluShadow on August 2, 2011 16:27
    spleen the last clause. Oops.

  • Error number invalid when using case when

    I have a table called NATIONAL_RARE_ECOSYSTEMS that contains 1 column called TEST_COLUMN (data type: varchar2):

    TEST_COLUMN
    rare ecosystem
    rare
    0
    0
    (null)
    (null)

    what I want is a query that will add a column called NRE_SCORE that will give each instance of line a score of 0 if it is null.
    If it is 0, then the score should be 0.
    If the line contains any text, partition should be 1

    I wrote the request:

    SELECT
    (CASE WHEN test_column is null THEN 0)
    WHEN test_column = 0 THEN 0
    WHEN test_column > 0, 1
    END) AS NRE_SCORE
    OF NATIONAL_RARE_ECOSYSTEMS;

    I get the error message:

    ORA-01722: invalid number
    01722 00000 - "invalid number."

    I think it is because on the 2nd and 3rd line, trying to perform arithmetic operations on a column which is varchar2 which I know that I can't do.

    How can I write a query that says: If the line contains text, then gives the score of 1?

    I'm using oracle 11g.

    Hello

    993451 wrote:
    I have a table called NATIONAL_RARE_ECOSYSTEMS that contains 1 column called TEST_COLUMN (data type: varchar2):

    TEST_COLUMN
    rare ecosystem
    rare
    0
    0
    (null)
    (null)

    what I want is a query that will add a column called NRE_SCORE that will give each instance of line a score of 0 if it is null.
    If it is 0, then the score should be 0.
    If the line contains any text, partition should be 1

    Any text other than '0', you mean. I guess that doesn't matter if this text is all the numbers, like '9876 'or something with no numbers, as 'rare'.

    I wrote the request:

    SELECT
    (CASE WHEN test_column is null THEN 0)
    WHEN test_column = 0 THEN 0
    WHEN test_column > 0 THEN 1
    END) AS NRE_SCORE
    OF NATIONAL_RARE_ECOSYSTEMS;

    I get the error message:

    ORA-01722: invalid number
    01722 00000 - "invalid number."

    I think it is because on the 2nd and 3rd line, trying to perform arithmetic operations on a column which is varchar2 which I know that I can't do.

    You are not actually doing arithmetic, but you compare your VARCHAR2 column, so he tries to convert the string to a NUMBER, and that's why you get the error ORA-01722.
    >

    How can I write a query that says: If the line contains text, then gives the score of 1?

    I'm using oracle 11g.

    Here's one way:

    SELECT       CASE
               WHEN  NVL (test_column, '0') = '0'
               THEN  0
               ELSE  1
           END          AS nre_score
    ,       ...          -- you must want other columns, too
    FROM       national_rare_ecosystems
    ;
    

    Since you are not really care on the numerical value, do not use numbers anywhere; stick with VARCHAR2s, for example '0'.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Point where the above query was to get erroneous results, and explain, using specific examples, how you get these results of the sample data in these palces.
    See the FAQ forum {message identifier: = 9360002}

  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                                      ))
                            overdue_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained in the data definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)
    My modified code is the following,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)
    Both approaches have the same problem.
    The output is in EXCEL format. The modified query works very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth like

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )
    

    for overdue_flag, which has more then 'Y' values of "n".
    If overdue_flag that in ('Y', ' don't) then

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )
    
  • Add case/When statement to display

    I am trying to add the Sub instruction 'case' in my opinion, but I get an error "invalid identifier" where he currently is now.

    CASE

    WHEN LATEST_EVENT_DT < "the Max event Date".

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as 'Max Event'

    CREATE OR REPLACE FORCE VIEWS GREATEST_DATE_VW_SGD
    ("PCFN"
    , "TCN.
    , "LATEST_EVENT_DT".
    , "LATEST_EVENT_DESC".
    , "OIT_Closed_Date".
    , "OIR_Closed_Date".
    , "OIN_Closed_Date".
    , "The Max event date".
    "Max Event")

    AS
    SELECT

    MV. PCFN,

    MV. TCN,

    MV LATEST_EVENT_DT.

    MV LATEST_EVENT_DESC.

    ILO. CLOSED_DATE,

    OIR. CLOSED_DATE,

    ISO. CLOSED_DATE,

    largest (mv. LATEST_EVENT_DT
    nvl (ILO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    nvl (OIR. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    nvl (ISO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    ) AS "event of Max Date."

    CASE
    WHEN LATEST_EVENT_DT < "the Max event Date".
    THEN "CANCELLED."
    OF OTHER LATEST_EVENT_DESC
    END as 'Max Event'

    OF APEX01. SGD_CIET_NDN_ROUTES_MV mv

    LEFT OUTER JOIN APEX01. OEF_ITV_TALLINN ILO ON mv. PCFN = ILO. PCFN AND mv. TCN = ILO. TCN

    LEFT OUTER JOIN APEX01. IRO OEF_ITV_RIGA ON mv. PCFN = IRO. PCFN AND mv. TCN = IRO. TCN

    LEFT OUTER JOIN APEX01. ISO of OEF_ITV_NDN ON mv. PCFN = ISO. PCFN AND mv. TCN = ISO. TCN;

    Is this possible? or do I have to create another view just for the case of "Max Event?

    CREATE OR REPLACE FORCE VIEW MAX_EVENT_DESC_SGD ('Max Event')

    AS

    SELECT THE CHECK BOX

    WHEN LATEST_EVENT_DT < "the Max event Date".

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as the "last event".

    OF greatest_date_vw_sgd g;

    Thank you

    Steven

    Post edited by: StevenD609

    Hello.

    Today, there is already this question...

    CREATE OR REPLACE FORCE VIEWS GREATEST_DATE_VW_SGD

    ("PCFN"

    , "TCN.

    , "LATEST_EVENT_DT".

    , "LATEST_EVENT_DESC".

    , "OIT_Closed_Date".

    , "OIR_Closed_Date".

    , "OIN_Closed_Date".

    , "The Max event date".

    "Max Event")

    AS

    SELECT

    Z.*,

    CASE

    WHEN LATEST_EVENT_DT< "max="" event="">

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as 'Max Event'

    Of

    (

    SELECT

    MV. PCFN,

    MV. TCN,

    MV LATEST_EVENT_DT.

    MV LATEST_EVENT_DESC.

    ILO. CLOSED_DATE,

    OIR. CLOSED_DATE,

    ISO. CLOSED_DATE,

    largest (mv. LATEST_EVENT_DT

    nvl (ILO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    nvl (OIR. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    nvl (ISO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    ) AS 'Max event Date.

    Of

    APEX01. SGD_CIET_NDN_ROUTES_MV mv

    LEFT OUTER JOIN APEX01. OEF_ITV_TALLINN ILO ON mv. PCFN = ILO. PCFN AND mv. TCN = ILO. TCN

    LEFT OUTER JOIN APEX01. IRO OEF_ITV_RIGA ON mv. PCFN = IRO. PCFN AND mv. TCN = IRO. TCN

    LEFT OUTER JOIN APEX01. ISO of OEF_ITV_NDN ON mv. PCFN = ISO. PCFN AND mv. TCN = ISO. TCN

    ) Z ;

  • Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition

    Hello

    I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:

    AND HOST_NAME IN

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER

    ("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")

    END

    )

    I get the following:

    ORA-00907: lack of right parenthesis

    00907 00000 - "lack the right parenthesis.

    But there is no missing parentheses!

    If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...

    I also tried:

    AND

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE

    HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")

    END

    )

    the error I get is:

    ORA-00905: lack of keyword

    00905 00000 - 'lack the key word'

    What keyword miss me?

    Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8

    Hello

    c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:

    It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)

    I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem.  Is it possible to re - write this?

    ...

    IF only works in PL/SQL.  It does not in SQL, even if that SQL is embedded in PL/SQL.

    There are many ways to re - write the condition.  And here's one:

    AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    )

    OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND TO_DATE (: StopDate, "MON-DD-YYYY")<  to_date="" ('dec-22-2015', ="">

    )

    )

    If: StopDate can be NULL, it must be a bit more complicated.

    You can also use nested, such as CASE expressions

    AND THE CASE

    WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    WHILE CASE

    WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND THEN 'OK '.

    END

    OTHER CASES

    WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND THEN 'OK '.

    END

    END = 'OK '.

    I wonder if this in your application is the best way, however.  If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table.  If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used.  Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.

  • Several SELECT statements with COUNTY with different WHERE clauses.

    OK, so for a bit of background on what this is trying to accomplish...
    I have a small group of people in my team and I will use GROUP BY for their names.
    If each person will be on their own line. Next to their names, I want to be able to have several columns that use the ACCOUNT for the different search criteria (no duplicates)

    Overall, it should have their names, and I would like to add the number of tickets that each person has which meet certain criteria (all in different columns)
    I have applications that can do each of these tasks, but is it possible that I can group together on a single table statements, or use subqueries for these results?

    Do you mean you want something like that?

    SQL > ed
    A written file afiedt.buf

    1 with the team (emp_id, emp_name)
    2 (select 1, 'Fred' from dual union all
    3. Select 2, 'Bob' Union double all the
    4. Select 3, 'Jim' to double
    5            )
    6, tickets (emp_id, ticket_type, ticket_id, ticket_desc)
    7 (select 1, 1, 'BUG', 'First billet Freds' double Union all)
    8. Select 2, 1, 'CHANGE', "Freds second ticket" of all the double union
    9 select 3, 1, 'BUG', ' Freds third ticket "of any double union
    10. Select 4, 2, "CHANGE", "Bobs first ticket" of any double union
    11. Select 5, 3, "CHANGE", "Jims first ticket" of any double union
    12. Select 6, 3, "BUG", "Jims second ticket" of all the double union
    13. Select 7, 1, 'BUG', ' Freds fourth ticket ' from dual
    14            )
    15-
    16 END OF TEST DATA
    17-
    18 select emp_name
    19, count (case when ticket_type = 'BUG' then 1 end to another null) and bugs
    20, count (case when ticket_type = 'CHANGE' then 1 end to another null) as changes
    21 of the team t
    22 a left join external tickets tk (t.emp_id = tk.emp_id)
    23 * emp_name group
    SQL > /.

    EMP_ CHANGES OF BUGS
    ---- ---------- ----------
    Bob           0          1
    Fred 3 1
    Jim           1          1

  • Need help with CASE When statement in a Where Clause

    So I have a SQL (simplified for this forum)

    Select t1.*
    from table1, table2 t2 t1
    where t1.field1 = t2.field1
    and when t1.field2 is null then trunc (sysdate) < = trunc (t1.date1 + 17)
    of another trunc (sydate) > = end of trunc (t2.date2 + t2.date3)

    I end up getting an error ORA-00905: lack of keyword

    I'm sure that I just got something here involved.

    You can not make the comparison within the statement underlying case like this. Assuming you have appropriate data types, something like this should work

    Select t1.*
    from table1 t1, table2 t2
    where t1.field1 = t2.field1
      and ((t1.field2 is null and
            trunc(sysdate) <= trunc(t1.date1 + 17)) or
           trunc(sydate) > = trunc(t2.date2 + t2.date3))
    

    John

  • Using a variable in the "LOVE" of a WHERE clause part

    How could I go to achieve this?

    I SELECT... WHERE AS 123% person_number';

    While observing the percent symbol, how I would substitute and explicit value with an implicit reference to a variable, I already assigned a value to?

    Thank you very much.

    don't know if that's what you need, but you can simply concatenate your variable with '% '.

    for example;

    SQL> select * from emp1 where job like 'A%';
    
         EMPNO JOB                  START_DAT        SAL       DEPT
    ---------- -------------------- --------- ---------- ----------
             3 Author
          4444 AUTHOR               24-MAY-10       5001          3
          3333 ANALYST              24-MAY-09       5004          2
    
    SQL> variable prefix char(1);
    SQL> exec :prefix :='A';
    
    SQL> select * from emp1 where job like :prefix||'%';
    
         EMPNO JOB                  START_DAT        SAL       DEPT
    ---------- -------------------- --------- ---------- ----------
             3 Author
          4444 AUTHOR               24-MAY-10       5001          3
          3333 ANALYST              24-MAY-09       5004          2
    
  • cases when for several columns

    Hello, Experts

    Could help me please on the function below. ?

    How to call two different columns in the instruction box.

    I'm migrating some of the BO decode OBIEE11g reports to help can we able to reach below senario in BO-universe but I don't know how we can achieve this in RPD - OBIEE 11 g

    DECODE (TABLE.NAME_1. Column_name, 'Client Meeting passwords', TABLE_NAME2. COLUMN, NULL)

    Concerning

    Sri

    Thanks for the reply Ceresa... !

    I use Case when statement... but I could not able to include more than one Table_Name.Coulmn_Name. the RPD

    For Ex in BO_Universe, it's logic has been used: DECODE (RPT.CUST_INFO.INFO_SUBTYPE,'Customer has past, RPT.) CUST_INFO. BODY, NULL)

    OBIEE: I'm trying to use like this: case when RPT.CUST_INFO.INFO_SUBTYPE,'Customer has past AND the RPT words. CUST_INFO. BODY = "NULL") END.

    ERROR: [nQSError: 27002] near <=>: syntax error [nQSError: 26012].

    Please guide me I missed something in the formula... ?

    I thank in advance. !

    Sri

  • Updated several lines using BOX WHEN

    I have the table ACCOUNT of structure as follows:

    Account_id ACCOUNT_STATUS
    0044607212
    0420562915
    6012720653

    I need to update the three rows at a time using a SELECT statement such that the second column will be respectively 5, 3, 2.
    I used the following query but it seems something is missing

    UPDATE ACCOUNT
    SET ACCOUNT_STATUS = CASE  
    WHEN ACCOUNT_STATUS = '004460721' THEN 5 
    WHEN ACCOUNT_STATUS = '042056291' THEN 3 
    WHEN ACCOUNT_STATUS = '601272065' THEN 2 
    WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 

     

    My question is this correct way? If not, I can use CASE WHEN statement and how or I only have the choice of use of SUB-SELECT to achieve this objective in a single statement?

    Don't know what SQLFiddle is and the DB, it uses, but it worked at Oracle 10.2.0.5:

    create table account (key primary number account_id,)
    account_status varchar2 (30));

    insert into a values (1, '5') account;
    insert into a values (2, '3') account;
    insert into a values (3, '2') account;

    update account

    Set the account_status CASE account_id =

    WHEN 1 then "2"

    WHEN THEN 2 '5'

    WHEN 3 THEN "3"

    END

    WHERE account_id IN (1,2,3);

    Select *.

    account;

    ACCOUNT_ID ACCOUNT_STATUS

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

    1                      2

    2                      5

    3                      3

  • Select the case when several returnvalue? 20 D

    Hello
    I would like to know if there is a solution less than 10g for something like this

    Select case when 'C' = 1
    then
    (select double 1,2,3,4,5)
    on the other
    (select double 6,7,8,9,0)
    end
    of the double.
    (select 1 double 'C')

    What I really need, is the full output of (select double 1,2,3,4,5) or (select double 6,7,8,9,0) If a State due to a different sql query is true or false. No matter if the solution uses 'case when' or anything else.

    Thanks in advance for any help.
    Best regards
    Carsten

    Something like this would work with the example you gave.

    SQL> with test_data as
      2      (select 1 c from dual)
      3  select
      4      1, 2, 3, 4, 5
      5  from
      6      dual,
      7      test_data
      8  where
      9      c = 1
     10  union all
     11  select
     12      6, 7, 8, 9, 0
     13  from
     14      dual,
     15      test_data
     16  where
     17      c != 1;
    
             1          2          3          4          5
    ---------- ---------- ---------- ---------- ----------
             1          2          3          4          5
    
    SQL> edi
    Wrote file afiedt.buf
    
      1  with test_data as
      2      (select 2 c from dual)
      3  select
      4      1, 2, 3, 4, 5
      5  from
      6      dual,
      7      test_data
      8  where
      9      c = 1
     10  union all
     11  select
     12      6, 7, 8, 9, 0
     13  from
     14      dual,
     15      test_data
     16  where
     17*     c != 1
    SQL> /
    
             1          2          3          4          5
    ---------- ---------- ---------- ---------- ----------
             6          7          8          9          0
    
  • Using decode in where clause

    Hello

    I need to use decode condition in where clause in such a way that if the respective column is null then consider the corresponding column

    for example

    Fee_dateFee_refund_date
    10 OCTOBER 05
    12 NOVEMBER 05
    11 JANUARY 06
    16 FEBRUARY 06

    I have a request in place as below where p_fee_flag will be passed as either FEES or set to null, I check another condition as if p_fee_flag is null then fee_date must be set to null when comparing fee_refund_date between TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE

    SELECT 1

    BUCKET BKT

    WHERE DECODE (P_FEE_FLAG, 'FEES', TRUNC(FS.) FEE_DATE), TRUNC (FS. FEE_REFUND_DATE))

    BETWEEN TRUNC (BKT. ACT_START_DATE) AND TRUNC (BKT. ACT_END_DATE)

    944524 wrote:

    Hello Alberto,.

    Thank you that's what I ask but is it possible to verify the condition even using decode

    Yes, it is possible, but why?

    Just replace the query in this way:

    select *
      from fee_table f
    where exists(select 1
                    from bucket b
                  where decode(:p_fee_flag, 'FEE', f.fee_date, f.fee_refund_date) between b.act_start_date and b.act_end_date)
      and decode(:p_fee_flag, 'FEE', null, f.fee_date) is null;
    

    Kind regards.

    Alberto

  • any case when and the sql clause

    Hello:
    What follows is my sql clause:
    SELECT T.*, b.name
    OF dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '% "| : ChineseName | ' %' AND b.name like "%" | : name | » %'
    ORDER BY t.ChineseName

    The main problem is that I want to check the b.name if it is null, it can be passed as function NVL, so I try using case when, but it does not work.
    When there are the b.name in where clause, the columns of result will not include data without b.name (or implies the b.name is NULL); And that
    the result data are not entirely accurate.
    is it possible to use the case when it is implemented in the following code snippet:

    -case when b.name is not NULL then b.name like "%" | : name | » %'
    Else b.name = NULL (b.name = b.name does not seem to work on the analysis of data zero)
    end

    Thank you very much.

    962769 wrote:
    The main problem is the table is the form of the cross, and the like clause will filter the
    data without a name. Basically, it should show the empty columns, however, it won't.
    so, when I test the sql code, I fhound Like "%" | b.Name | ' %' will not get the data when the original dbtest1 table data
    has no id corresponding to the BD test. It seems pointless to go the LEFT OUTER JOIN.

    Thank you

    WHERE t.ChineseName like '%'||:ChineseName||'%'
    AND  (
            b.name like '%'||:name||'%'
           or b.empno is null
        )
    

Maybe you are looking for

  • For iPhone5 and Air2 iPad car chargers

    I have 2 iPhone 5 s and 2 iPads. An iPad is iPad Air2 and the other is an older iPad in 4 years. What types of car chargers will maintain loaded safely and as soon as it is reasonable within the limits of the 12V car system? I have read and received

  • A gray screen at startup - no solution doesn't work?

    Since I upgraded to El Capitan my iMac has been a nightmare and it was fantastic before!  This week it stopped loading altogether; If I start it normally, it brings up a loading bar then gets just stuck to the end, if I load in SafeMode it show the l

  • I want to copy the bookmark links and stick them on a text document. Is there a quick way to do it?

    I have too many bookmarks and want to put just the links in text documents. Problem is it takes too long and I was wondering if there was a faster way to do it.

  • Toshiba satellite 220cs! I NEED HELP

    I have a card Xircom RealPort CardBus Ethernet 10 / 100 + Modem 56 k (model RBEM56G-100), but when I try to insert into the pcmcia slot on my laptop, the card is not detected. However, when I try to insert a card Xircom CreditCard Ethernet 10 / 100 +

  • Problem of current drawing of digital entry into PCI-6220

    We have card NI PCI-6220 mounted on card PCI-Raiser in a windows PC mini. We are using 8-channel digital input P1.4 - P1.7 and P2.2 - P2.5 to take a few entries of our entry card. When the computer is turned on then everything works well and we get o