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 )

Similar Messages

  • 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 '<', '>', '='

  • 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

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

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

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

  • Invalid number error when using case when

    I have table called NATIONAL_RARE_ECOSYSTEMS which has 1 column called TEST_COLUMN (data type: varchar2):
    TEST_COLUMN
    rare ecosystem
    rare
    0
    0
    (null)
    (null)
    what I want is a query which will add a column called NRE_SCORE which will give each row instance a score of 0 if it null.
    If it is 0 then score should be 0.
    If the row contains any text then score should be 1
    I have written the query:
    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
    FROM NATIONAL_RARE_ECOSYSTEMS;
    I get the error message:
    ORA-01722: invalid number
    01722. 00000 - "invalid number"
    I think this is because on the 2nd and 3rd line I'm trying to do arithmetic on a column which is varchar2 which I know I cant do.
    How do I write a query which says: if the row contains text then give score of 1?
    I'm using oracle 11g.

    Hi,
    993451 wrote:
    I have table called NATIONAL_RARE_ECOSYSTEMS which has 1 column called TEST_COLUMN (data type: varchar2):
    TEST_COLUMN
    rare ecosystem
    rare
    0
    0
    (null)
    (null)
    what I want is a query which will add a column called NRE_SCORE which will give each row instance a score of 0 if it null.
    If it is 0 then score should be 0.
    If the row contains any text then score should be 1Any text other than '0', you mean. I assume it doesn't matter if that text happens to be all digits, such as '9876', or something with no digits, such as 'rare'.
    I have written the query:
    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
    FROM NATIONAL_RARE_ECOSYSTEMS;
    I get the error message:
    ORA-01722: invalid number
    01722. 00000 - "invalid number"
    I think this is because on the 2nd and 3rd line I'm trying to do arithmetic on a column which is varchar2 which I know I cant do.You're actually not doing any arithmetic, but you are comparing your VARCHAR2 column to a NUMBER, so it tries to convert the string to a NUMBER, and that's why you get the ORA-01722 error.
    >
    How do I write a query which says: if the row contains text then give 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 don't really care about the numeric value, don't use NUMBERs anywhere; stick with VARCHAR2s, such as '0'.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Point out where the query above is getting the wrong results, and explain, using specific examples, how you get those results from the sample data in those palces.
    See the forum FAQ {message:id=9360002}

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

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

  • Obiee nested case when statements

    Hi Obiee Experts, I need to retrieve amounts for 'last september' so i created a column using this case statement: case when MONTH(CURRENT_DATE) <= 9 then (YEAR(CURRENT_DATE) -1) * 100 + 9 END  --  now i want to retrieve the amount for last september using another case statemnt but i get a syntax err message, when i use: CASE WHEN (case when MONTH (CURRENT_DATE) <= 9 then (YEAR(CURRENT_DATE) -1) * 100 + 9 END) THEN "Fact123"."Net Obligation Amount" END ---- Any ideas how to resolve? I will be forever grateful - cheers, Elena

    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.

  • Doubt in case when statement

    hi gems...
    i have a case when statement in a select clause...there are total three conditions in the case when statemnt.
    now my question is if all theconditions gets matched, then what will happen???
    is only first condition gets executed and rest two will be ignored or the third condition will overwrite the previous two???
    please help...thanks in advance...

    Hello
    This isn't very difficult to test....
    select
         CASE
              WHEN 1=1 THEN
                1
              WHEN 1=1 THEN
                2
              WHEN 1=1 THEN
                3
         END c
    FROM
         dual
             C
             1
    1 row selected.It wil return the first match.
    David

Maybe you are looking for

  • Help with XML, display data on swipe/click

    Hello. I am trying to create a moibile app that displays XML data. It's basically a phone book. I want the data to change when swiped. I can get the data in just fine. I can get it to display fine. I am not seeing the correct image first, however. I

  • Objects on Java Engine or Abap Engine. Pls sugget

    Hi All, Pls let me know: 1. Mapping Runtime, SLD, Adapters (except IDOC and HTTP sender) run on Java Engine? 2. BPE and IE are on Abap Engine? 3. CPA_cache refreshes objects of IR and ID present in    Java Engine? 4, SXI_CACHE refreshes objects of IR

  • Java.lang.IllegalStateException: duplicate Id for a component

    Hi everyone, please I'm really having a serious issue on the duplicate id for a component in view. I have a page of which I used the <jsp:include> tag to add to some pages of my application. The page have the following code snippet in it <%@taglib pr

  • I can't open my *tdv - files

     I can't open my *tdv - files i made two months ago in diadem view. I run diadem 9.1.SP2c on Windows XP SP2 and we have Macaffee Enterprise 8i.When i make a new *tdv - file and save it, i can open it properly.

  • Arch Vs HP Mini 100-4100

    Hi All, i'm a new user on Arch, i come from other distro's (debian/ubuntu - fedora) i spend the day following a lot of wiki's and guides in order to install Arch on my netbook. The problem is: X doesn't start. surely i made a lot mistake on the insta