Using case when statement or decode stament in where clause

hi gems..
i have a problem in the following query..
i am trying to use case when statement in the where clause of a select query.
select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
cr.salary as salary
from customer_details cr
where (case when '>' = '>' then 'cr.salary > 5000'
when '>' = '<' then 'cr.salary < 5000'
when '>' = '=' then 'cr.salary = 5000'
else null
end);
the expression in the when clause of the case-when statement will come from UI and depending on the choice i need to make the where clause.
thats why for running the query, i have put '>' in that place.
so the original query will look like this(for your reference):
select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
cr.salary as salary
from customer_details cr
where (case when variable = '>' then 'cr.salary > 5000'
when variable = '<' then 'cr.salary < 5000'
when variable = '=' then 'cr.salary = 5000'
else null
end);
so, in actual 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 am getting the error "ORA 00920:invalid relational operator"
please help..thanks in advance..

Hi,
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
       )Edited by: user6806750 on 22.12.2011 14:56
For some reason I can't write in sql '<', '>', '='

Similar Messages

  • Using case when statement in the select query to create physical table

    Hello,
    I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
    I have a physical table based on a select table with one column.
    SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
    I also have a customer table.
    In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
    In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
    EXECUTION
    When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
    everything works as expected. YE!!
    Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
    SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
    FROM DUAL
    Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
    surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
    If anyone has any explanation to this error and how we can achieve the same, please help.
    Thanks.

    Hello,
    Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
    I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
    Here is what I am trying to do. the select query of the physical table is as follows.
    SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
    The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
    Thanks.

  • How to use case when statements in ODI

    I need to put conditional logic before DVM look up in ODI. In the expression editor I put the following statement:-
    CASE WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS' THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=EBIZ_CELL.CELL_DATA
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC' THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=EBIZ_CELL.CELL_DATA
    END
    It did not work,
    Under Operators ->All Executions, found the error:-
    905 : 42000 : java.sql.SQLException: ORA-00905: missing keyword
    The description in Session Task contained:-
    select     
         C1_JOURNAL_TEMPL
    from     APPS.POC_JOURNAL_TEMP_SOURCE_TBL POC_JOURNAL_TEMP_SOURCE_TBL, APPS.C$_0POC_JOURNAL_TEMP_TARGET_TB
    where     
         (1=1)
    And (CASE
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
    THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME=C2_CELL_DATA
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
    THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)=C2_CELL_DATA
    END)
    Checked the above code in PL/SQL Developer but it gave errors.
    In PL/SQL developer tried to check a simple query using case-when but even that is giving errors in the case-when portion.
    The query is as follows:-
    select phase_code, accounting_period, sum(eff_cc) as BD_Eff_QTD
    from prj_detail
    where
    case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    when 'EXT'
    then
    1
    when 'RAC'
    then
    2
    when 'XXX'
    then
    3
    else
    end
    I would like to know what is wrong with the above code.
    Please let me know what is the correct way of using case-when in PL/SQL as well as in ODI.

    Your ODI case statement and PL/SQL Case statement both looks confusing.
    You are writing case statement under where clause which is not a good practise. If you want to implement logic like-
    select a,b,c from <table>
    where
    when cond^n^ 1 then do 1
    when cond^n^ 2 then do 2
    then better you seperate your query for each filter and do a union, in other words-
    select a,b,c from <table>
    where cond^n^ 1
    union
    select a,b,c from <table>
    where cond^n^ 2
    If you are writing case staement to retrieve a value/column (EBIZ_CELL.CELL_DATA) then no need to include it under filter.
    ODI case for column EBIZ_CELL.CELL_DATA will be:
    CASE
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='RCS'
    THEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    WHEN POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME='FDC'
    THEN CONCAT(POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME,POC_JOURNAL_TEMP_SOURCE_TBL.BOOK_CODE)
    END
    Pl/SQL query-
    select phase_code, accounting_period,
    case POC_JOURNAL_TEMP_SOURCE_TBL.APPLICATION_NAME
    when 'EXT'then 1
    when 'RAC' then 2
    when 'XXX' then 3
    else 'default value' --- (if no else needed then can also remove else part)
    end,
    sum(eff_cc) as BD_Eff_QTD
    from prj_detail
    Suggested as per what is understood, hope it helps.
    Edited by: 939451 on Jul 5, 2012 12:47 AM
    Edited by: 939451 on Jul 5, 2012 12:48 AM

  • CASE WHEN statement in DECODE

    SELECT v_startdate, v_enddate,
    (CASE WHEN SYSDATE BETWEEN v_startdate AND v_enddate THEN
    ‘active’
    ELSE
    ‘inactive’
    END) status
    FROM correction_tab;
    Could you kindly guide us as to how can we use DECODE and get the desired output.
    Thanks,
    Rami Reddy.

    You can, like this.
    However, the CASE seems a lot clearer to me so why bother with a DECODE?
    sql> with correction_tab as
      2    ( select trunc(sysdate)-1 as v_startdate, trunc(sysdate)   as v_enddate from dual
      3    union all
      4      select trunc(sysdate)   as v_startdate, trunc(sysdate)+1 as v_enddate from dual
      5    union all
      6      select trunc(sysdate)+1 as v_startdate, trunc(sysdate)+2 as v_enddate from dual
      7    )
      8  SELECT v_startdate
      9  ,      v_enddate
    10  ,      CASE
    11           WHEN SYSDATE BETWEEN v_startdate AND v_enddate
    12             THEN 'active'
    13           ELSE 'inactive'
    14         END status
    15  ,      decode ( sign(sysdate-v_startdate), 1, decode(sign(v_enddate-sysdate), 1, 'active', 'inactive'), 'inactive')
    as status2
    16  FROM correction_tab
    17  /
    V_STARTDA V_ENDDATE STATUS   STATUS2
    12-DEC-12 13-DEC-12 inactive inactive
    13-DEC-12 14-DEC-12 active   active
    14-DEC-12 15-DEC-12 inactive inactive

  • Using Case when statement in catalog doesnt result in the correct sql

    I am running into an issue on my current project wherein, I am not able to see the correct formula in the physical query as I am seeing it in the logical query:
    Logical query:
    SET VARIABLE QUERY_SRC_CD='Report',SAW_SRC_PATH='/shared/Email/SFDC_InitRespTimel_Main';SELECT s_0, s_1, s_2, s_3, s_4, s_5 FROM (
    SELECT
    0 s_0,
    "CIN"."Calendar"."FIis Yr Nm" s_1,
    "CIN"."Calendar"."Fis Qtr Nm" s_2,
    "CIN"."SF Origin Dim"."Group" s_3,
    **CASE WHEN MIN("CIN"."SF_EailMsg_L"."Msg Dt") IS NOT NULL THEN SUM(TIMESTAMPDIFF(SQL_TSI_HOUR,MIN("SF_EailMsg_L"."Msg Dt"),"CIN"."SF_Case_L_Fact"."Created Dt"))/count("CIN"."SF_Case_L_Fact"."Case Number") END s_4,**
    **REPORT_AGGREGATE(CASE WHEN MIN("CIN"."SF_EailMsg_L"."Msg Dt") IS NOT NULL THEN SUM(TIMESTAMPDIFF(SQL_TSI_HOUR,MIN("SF_EailMsg_L"."Msg Dt"),"CIN"."SF_Case_L_Fact"."Created Dt"))/count("CIN"."SF_Case_L_Fact"."Case Number") END BY "CIN"."Calendar"."Fis Qtr Nm","CIN"."SF Origin Dim"."Group") s_5**
    FROM "CIN"
    WHERE
    (("Calendar"."FISCAL_YEAR_NAME" IN ('FY2011', 'FY2012', 'FY2013')) AND ("SF_EailMsg_L"."Status" = '3') AND ("Calendar"."FISCAL_QUARTER_NAME" <> 'Q1 FY2011'))
    ) djm ORDER BY 1, 2 ASC NULLS LAST, 3 ASC NULLS LAST, 4 ASC NULLS LAST
    Physical Query:
    select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4
    from
    (select T13596.CRTDDT_DT as c1,
    T4813.FISCAL_YEAR_NAME as c2,
    T4813.FISCAL_QUARTER_NAME as c3,
    T13313.GRP as c4,
    ROW_NUMBER() OVER (PARTITION BY T4813.FISCAL_QUARTER_NAME, T13313.GRP, T13596.CRTDDT_DT ORDER BY T4813.FISCAL_QUARTER_NAME ASC, T13313.GRP ASC, T13596.CRTDDT_DT ASC) as c5
    from
    DW_SF_EMLMSSG_L T13275,
    SF_ORGN_L_DIM T13313,
    CIN_CALENDARS_DIM T4813,
    DW_SF_CS_L T13596 /* SF_CS_L_Fact */
    where ( T4813.CALENDAR_KEY = T13596.CRDT_KEY and T13275.PRNTID = T13596.ID and T13275.STTS = '3' and T13313.ORGN_KEY = T13596.ORGN_KEY and (T4813.FISCAL_YEAR_NAME in ('FY2011', 'FY2012', 'FY2013')) and T4813.FISCAL_QUARTER_NAME <> 'Q1 FY2011' )
    ) D1
    where ( D1.c5 = 1 )
    WITH
    SAWITH0 AS (select min(T13275.MSSGDT_DT) as c1,
    count(T13596.CSNMBR) as c2,
    T4813.FISCAL_YEAR_NAME as c5,
    T4813.FISCAL_QUARTER_NAME as c6,
    T13313.GRP as c7
    from
    DW_SF_EMLMSSG_L T13275,
    SF_ORGN_L_DIM T13313,
    CIN_CALENDARS_DIM T4813,
    DW_SF_CS_L T13596 /* SF_CS_L_Fact */
    where ( T4813.CALENDAR_KEY = T13596.CRDT_KEY and T13275.PRNTID = T13596.ID and T13275.STTS = '3' and T13313.ORGN_KEY = T13596.ORGN_KEY and (T4813.FISCAL_YEAR_NAME in ('FY2011', 'FY2012', 'FY2013')) and T4813.FISCAL_QUARTER_NAME <> 'Q1 FY2011' )
    group by T4813.FISCAL_QUARTER_NAME, T4813.FISCAL_YEAR_NAME, T13313.GRP)
    select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7
    from
    (select D1.c1 as c1,
    D1.c2 as c2,
    min(D1.c1) over (partition by D1.c6, D1.c7) as c3,
    sum(D1.c2) over (partition by D1.c6, D1.c7) as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7,
    ROW_NUMBER() OVER (PARTITION BY D1.c6, D1.c7 ORDER BY D1.c6 ASC, D1.c7 ASC) as c8
    from
    SAWITH0 D1
    ) D1
    where ( D1.c8 = 1 )
    I want to know if you have seen this scenario earlier?
    Basically, the case statement in the logical sql is not getting executed correctly in the physical sql. Also,I see a SAWWITH0 in the query. Have you seen this before.
    If you have any inputs on how to fix this, please share.
    Thanks in advance.
    -Mayank Sharma

    Hello,
    This is the logical and physical query that I am getting now.
    My question is that, why am I not seeing the division operator (/) anywhere in the physical query. I am worried that the physical query is not being executed correctly.
    Please clarify:
    SET VARIABLE QUERY_SRC_CD='Report',SAW_DASHBOARD='/shared/Email/Email',SAW_DASHBOARD_PG='Initial Resp Time',SAW_SRC_PATH='/shared/Email/SFDC_InitRespTimel_Main';SELECT s_0, s_1, s_2, s_3, s_4, s_5 FROM (
    SELECT
    0 s_0,
    "CIN"."Calendar"."FIis Yr Nm" s_1,
    "CIN"."Calendar"."Fis Qtr Nm" s_2,
    "CIN"."SF Origin Dim"."Group" s_3,
    CASE WHEN MIN("CIN"."SF_EailMsg_L"."Msg Dt") IS NOT NULL THEN SUM(TIMESTAMPDIFF(SQL_TSI_HOUR,MIN("SF_EailMsg_L"."Msg Dt"),"CIN"."SF_Case_L_Fact"."Created Dt"))*1.0/count("CIN"."SF_Case_L_Fact"."Case Number")*1.0 END s_4,
    REPORT_AGGREGATE(CASE WHEN MIN("CIN"."SF_EailMsg_L"."Msg Dt") IS NOT NULL THEN SUM(TIMESTAMPDIFF(SQL_TSI_HOUR,MIN("SF_EailMsg_L"."Msg Dt"),"CIN"."SF_Case_L_Fact"."Created Dt"))*1.0/count("CIN"."SF_Case_L_Fact"."Case Number")*1.0 END BY "CIN"."Calendar"."Fis Qtr Nm","CIN"."SF Origin Dim"."Group") s_5
    FROM "CIN"
    WHERE
    (("Calendar"."FISCAL_YEAR_NAME" IN ('FY2011', 'FY2012', 'FY2013')) AND ("SF_EailMsg_L"."Status" = '3') AND ("Calendar"."FISCAL_QUARTER_NAME" <> 'Q1 FY2011'))
    ) djm ORDER BY 1, 2 ASC NULLS LAST, 3 ASC NULLS LAST, 4 ASC NULLS LAST
    [2012-10-25T22:20:58.000+00:00] [OracleBIServerComponent] [TRACE:2] [USER-23] [] [ecid: a5bccb33dce3bd12:-c49596b:13a898b42b5:-8000-0000000000007756] [tid: 601c] [requestid: 1d4c0001] [sessionid: 1d4c0000] [username: weblogic] -------------------- General Query Info: [[
    Repository: Star, Subject Area: CIN, Presentation: CIN
    [2012-10-25T22:20:58.000+00:00] [OracleBIServerComponent] [TRACE:2] [USER-18] [] [ecid: a5bccb33dce3bd12:-c49596b:13a898b42b5:-8000-0000000000007756] [tid: 601c] [requestid: 1d4c0001] [sessionid: 1d4c0000] [username: weblogic] -------------------- Sending query to database named CIN (id: <<177780>>), connection pool named CINADMIN: [[
    select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4
    from
    (select T13596.CRTDDT_DT as c1,
    T4813.FISCAL_YEAR_NAME as c2,
    T4813.FISCAL_QUARTER_NAME as c3,
    T13313.GRP as c4,
    ROW_NUMBER() OVER (PARTITION BY T4813.FISCAL_QUARTER_NAME, T13313.GRP, T13596.CRTDDT_DT ORDER BY T4813.FISCAL_QUARTER_NAME ASC, T13313.GRP ASC, T13596.CRTDDT_DT ASC) as c5
    from
    DW_SF_EMLMSSG_L T13275,
    SF_ORGN_L_DIM T13313,
    CIN_CALENDARS_DIM T4813,
    DW_SF_CS_L T13596 /* SF_CS_L_Fact */
    where ( T4813.CALENDAR_KEY = T13596.CRDT_KEY and T13275.PRNTID = T13596.ID and T13275.STTS = '3' and T13313.ORGN_KEY = T13596.ORGN_KEY and (T4813.FISCAL_YEAR_NAME in ('FY2011', 'FY2012', 'FY2013')) and T4813.FISCAL_QUARTER_NAME <> 'Q1 FY2011' )
    ) D1
    where ( D1.c5 = 1 )
    [2012-10-25T22:20:58.000+00:00] [OracleBIServerComponent] [TRACE:2] [USER-18] [] [ecid: a5bccb33dce3bd12:-c49596b:13a898b42b5:-8000-0000000000007756] [tid: 601c] [requestid: 1d4c0001] [sessionid: 1d4c0000] [username: weblogic] -------------------- Sending query to database named CIN (id: <<178213>>), connection pool named CINADMIN: [[
    select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7
    from
    (select D1.c1 as c1,
    D1.c2 as c2,
    min(D1.c1) over (partition by D1.c6, D1.c7) as c3,
    sum(D1.c2) over (partition by D1.c6, D1.c7) as c4,
    D1.c5 as c5,
    D1.c6 as c6,
    D1.c7 as c7,
    ROW_NUMBER() OVER (PARTITION BY D1.c6, D1.c7 ORDER BY D1.c6 ASC, D1.c7 ASC) as c8
    from
    (select min(T13275.MSSGDT_DT) as c1,
    count(T13596.CSNMBR) as c2,
    T4813.FISCAL_YEAR_NAME as c5,
    T4813.FISCAL_QUARTER_NAME as c6,
    T13313.GRP as c7
    from
    DW_SF_EMLMSSG_L T13275,
    SF_ORGN_L_DIM T13313,
    CIN_CALENDARS_DIM T4813,
    DW_SF_CS_L T13596 /* SF_CS_L_Fact */
    where ( T4813.CALENDAR_KEY = T13596.CRDT_KEY and T13275.PRNTID = T13596.ID and T13275.STTS = '3' and T13313.ORGN_KEY = T13596.ORGN_KEY and (T4813.FISCAL_YEAR_NAME in ('FY2011', 'FY2012', 'FY2013')) and T4813.FISCAL_QUARTER_NAME <> 'Q1 FY2011' )
    group by T4813.FISCAL_QUARTER_NAME, T4813.FISCAL_YEAR_NAME, T13313.GRP
    ) D1
    ) D1
    where ( D1.c8 = 1 )

  • Using more than one case when statement

    Hi there,
    I have a question on using case when statements.
    Currently I have a table where it shows me mulitple dates.
    Order Saledate TransferDate StartDate Enddate GetDate
    I have created a where statement to show me records against the transferdate dependant if it appears within the date range of the year, or if it appears within the startdate and today's date.
    (lpatran.trandate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate() end))
    However on some of the records the transfer date is null, and so they want to use the saledate as the date to use.
    So I created
    (case when Lpatran.trandate is not null then (Lpatran.trandate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate()))
    else (lpatran.saledate between targets.startdate
    and (case when targets.enddate < getdate() then targets.enddate else getdate())) end )
    However it gives me an incorrect syntax near the word ‘between ‘ 
    Is there a simple fix for this or does sql not allow me to do this?

    I have created a new column called transferdate and done a case when statement
    CASE
    WHEN lpatran.trandate
    IS
    NULL
    THEN lpatran.saledate
    ELSE lpatran.trandate
    END
    AS Transferdate,
    Then created a temptable and did a select * from temptable.  Created a where statement from transferdate, which does work and gives me the correct data. 
    TransferDate between startdate
    and(case
    when enddate
    <
    getdate()
    then enddate
    else
    getdate()
    end))
    However I wanted to know if there was a way of obtaining the same data without having to use the temptable ?

  • Update multiple rows using CASE WHEN

    I have the table ACCOUNT of structure as follow: 
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something 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 way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?

    Hi,
    Hawk333 wrote:
    I have the table ACCOUNT of structure as follow:
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something 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 way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?
    What happens when you try it?
    Did you mean "WHEN ACCOUNT_ID = ..."?
    A CASE expressions always needs an END keyword.
    Depending on your requirements (that is, why are those rows being changed, and how do you determine the new values) a CASE expression in an UPDATE statement, similar to what you posted, could be a good way to do it.  MERGE (instead of UPDATE) would also be an option, especially if you want to avoid updating rows that already happen to have the correct values.

  • Insert using case when

    hello ,
    i wanna use "case when" statement in the insert , i implement it like this :
    currentyear:=1;
    insert into test1 (ATTRIB1,ATTRIB2) values ((case when currentyear=1 then 'ok' else 'notOK' end),'val2' );
    but it didn't work, i got this error :
    ORA-14551: cannot perform a DML operation inside a query
    Regards
    Elyes
    Edited by: user10393090 on 5 janv. 2009 03:32

    Better approach is ->
    insert into test1 (ATTRIB1,ATTRIB2)
    select case
             when &currentyear=1 then
              'ok'
           else
             'notOK'
           end AS attrib1,
           'val2' AS attrib2
    from dual;N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Using CASE WHEN to change background color

    I've done this many times without any problems, but this time its a little different situation and I can't get it to work.
    I can use this CASE WHEN statement without any problems.
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where
    EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    '<span style="color:brown;background-color:yellow">'||NAME||'</font>'
    ELSE "NAME"
    END
    "NAME",
    But I Cant Get This One to Work
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where
    EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    '<span style="color:brown;background-color:yellow">'||NAME_DISPLAY||'</font>'
    ELSE "NAME"
    END
    "NAME" NAME_DISPLAY,
    I'm sure that the problem lies with <"NAME" NAME_DISPLAY> but I can't find my way to a solution.
    Does anyone have any ideas for me?

    I've done this many times without any problems, but this time its a little different situation and I can't get it to work.
    I can use this CASE WHEN statement without any problems.
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    (ignore this) span style="color:brown;background-color:yellow">'||NAME||' (ignore this)
    ELSE "NAME"
    END
    "NAME",
    But I Cant Get This One to Work
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    (ignore this) span style="color:brown;background-color:yellow">'||NAME||' (ignore this)
    ELSE "NAME"
    END
    "NAME" NAME_DISPLAY,
    I'm sure that the problem lies with <"NAME" NAME_DISPLAY> but I can't find my way to a solution. Does anyone have any ideas for me?

  • How to create nested case when statement in OBIEE 11g?

    Hi All,
    I need to create a formula using nested case when statement. The formula to be created is below:
    =If([AWRV]<0; "<0";
    If([AWRV]=0; "0";
    If([AWRV]<=15; ">0 and <=15";
    If([AWRV]<=25; ">15 and <=25";
    If([AWRV]<=50; ">25 and <=50";
    If([AWRV]<=75; ">50 and <=75";
    If([AWRV]<=100; ">75 and <=100";
    If([AWRV]<=200; ">100 and <=200";
    If([AWRV]<=500; ">200 and <=500";
    If([AWRV]<=1000; ">500 and <=1000";
    If([AWRV]<=5000; ">1000 and <=5000";
    If([AWRV]<=10000; ">5000 and <=10000"; ">10000"))))))))))))
    How to recreate using Nested case when? I tried in many different ways but it is displaying syntax error in obiee11g. This is very critical. Can anybody shed light on this issue pls?
    Thanks in advance,
    Thenmozhi

    Honey26 wrote:
    Hi All,
    I need to create a formula using nested case when statement. The formula to be created is below:
    =If([AWRV]<0; "<0";
    If([AWRV]=0; "0";
    If([AWRV]<=15; ">0 and <=15";
    If([AWRV]<=25; ">15 and <=25";
    If([AWRV]<=50; ">25 and <=50";
    If([AWRV]<=75; ">50 and <=75";
    If([AWRV]<=100; ">75 and <=100";
    If([AWRV]<=200; ">100 and <=200";
    If([AWRV]<=500; ">200 and <=500";
    If([AWRV]<=1000; ">500 and <=1000";
    If([AWRV]<=5000; ">1000 and <=5000";
    If([AWRV]<=10000; ">5000 and <=10000"; ">10000"))))))))))))
    How to recreate using Nested case when? I tried in many different ways but it is displaying syntax error in obiee11g. This is very critical. Can anybody shed light on this issue pls?
    Thanks in advance,
    ThenmozhiTry the below:
    CASE WHEN "Fact - Open Chargeback"."Sub Chbk Amt" < 0 THEN ' <0'
    WHEN "Fact - Open Chargeback"."Sub Chbk Amt" = 0 THEN '0'
    WHEN "Fact - Open Chargeback"."Sub Chbk Amt" BETWEEN 0 AND 15 THEN '>0 AND <=15'
    END
    Hope this helps.

  • Using :case when  in where clause

    Hello,
    I need some help with using of case statement in a where clause
    Table that contains info about employees taking some coursework:
    Class (values could be SAP, ORACLE, JAVA)
    Code (if Class is SAP then CODE is not null; if class is any other CODE is NULL)
    Start Date (date they began class not null)
    End Date (date then ended the class - could be null)
    Employee Level(numbers from one through five)
    I need a single LOV in forms that should show Employee_Level for input class,code,date.
    How to do this?
    I started off with this but get 'missing statement error'
    select distinct employee_level from e_course
       where (
       case when &class='SAP' then code ='1' and start_date > to_date('20000101','YYYYMMDD') and
                                               end_date < to_date('20000101','YYYYMMDD')
               else
                   null
       end) order by employee_level;Thanks

    Hi,
    user469956 wrote:
    But all these examples have only one condition for each case.Depending on how you count, all WHERE clauses have only one condition.
    I see an example in that thread that has 6 atomic conditions, linked by AND and OR.
    I need to check date & code. This is what is causing the error.Why do you want to use a CASE statement?
    Why can't you put all your conditions directly iinto a WHERE clause, soemthing like this:
    WHERE   (   &class='SAP'
            AND code ='1'
    OR      (   start_date  > to_date('20000101','YYYYMMDD')
            AND end_date    < to_date('20000101','YYYYMMDD')
            )I said "something like this" because I don't know what you really want to do.

  • "IN" operator in Case When statement

    Hi
    When I'm trying to use "IN" operator in the "Case When" statement , the following error is being displayed : " [nQSError: 27002] Near <In>: Syntax error [nQSError: 26012] " .
    Please let me know wether we can use "IN" oprerator in the Case When statement.
    Thanks.

    Hi
    Below is the code in which I'm trying to use "IN" operator in the CASE WHEN statement :
    CASE WHEN Month=1 then Year IN (2009,2010) else 0 end
    Above - (Year and month are of integer datatype, hence i did not use single quotes)
    Thanks

  • Is Prompted (Case When Statement)

    I created a column in an answers report and used a CASE WHEN statement as the formula. I set this column to an Is Prompted filter. But when i try to run the report from the dashboard prompt, it just ignores this filter. What am i doing wrong?

    Hello,
    Prompt also should contain the same case when condition in it's fx so that.. when you say is prompted on that code in answers, prompt value will be effected in the answers.
    Else assign a presentation variable to the prompt (if it's drop - down controlled), and use that presentation variable in the filter section of your request...
    Hope you get it..

  • Using Case When

    I have a situation where i need to write a case when sql expression to fetch certain rows from a table.
    How to use CASE WHEN THEN ELSE END in a report query ?
    Explanation with a simple example will be of great help.
    thanks

    The javadoc for oracle.toplink.expressions.Expression
    contains some information.
    The following is an example of how to build the case statement.
    This will use case to replace the keys in the caseTable with the values. The default value (the ELSE) is provided as the second argument.
         Hashtable caseTable = new Hashtable(3);
         caseTable.put("Bob", "Bobby");
         caseTable.put("Susan", "Susie");
         caseTable.put("Eldrick", "Tiger");
         Expression expression = builder.get("firstName").caseStatement(caseTable, "No-Nickname").equal("Bobby");

  • Case When instead of Decode

    Hi,
    How to convert this decode statements into CASE WHEN syntax
    phone_v := DECODE (c_rec.phone, NULL, NULL, DECODE ( is_it_number (c_rec.phone), 'F', DBMS_RANDOM.STRING ('a', LENGTH (c_rec.phone)), SUBSTR                                                             (DBMS_RANDOM.VALUE, 2, LENGTH (c_rec.phone))));
    thanks, Bcj

    That should be easiest written like the following :
    phone_v := DECODE (c_rec.phone
                      , NULL, NULL
                      , DECODE ( is_it_number (c_rec.phone)
                                , 'F', DBMS_RANDOM.STRING ('a', LENGTH (c_rec.phone))
                                , SUBSTR (DBMS_RANDOM.VALUE, 2, LENGTH (c_rec.phone))
                      );Is it ?
    Nicolas.

Maybe you are looking for

  • How to use new aluminum apple remote with an imac

    How does it work?  Menu button doesn't seem to do anything.  I paired it io and got the linking chain icon.  The volume up down works, and sometimes the left right buttons move itunes to the next selection, but that's it.  I was not able to find an o

  • Cannot get windows 7 to install on new imac

    I have a new "Thunderbolt" imac. Using the boot camp assistant disk that came with it (or the downloaded one), I cannot get windows 7 successfully installed. Mostly won't start up. Long hang-ups, mouse won't work. Have used Boot Camp on older mac Pro

  • Safari crashes without warning almost every time I use it. I really need to fix this!

    Here is my crash report. Process:         WebProcess [2514] Path: /System/Library/PrivateFrameworks/WebKit2.framework/WebProcess.app/Contents/Mac OS/WebProcess Identifier:      com.apple.WebProcess Version:         8536 (8536.30.1) Build Info: WebKit

  • Can I slow down the rate of movement at end of a Ken Burns?

    And can I bring up a still, then have the burns effect begin aftyer a second or so?

  • Export customers line item clearing

    Hi all supporters, When am going to clear the export customers invoice in local currency on current date,it gives me the inv.foreing curr.amt as per current exchange rate, but i want the base exchange rate i.e.the rate by which the inv.is made. can a