Case Statement in Answers Filter

Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
Thx

ziekc wrote:
Hi,
I'm trying to build a query in Answers that filters the data returned based on the current month number. If the current month is 1 then we want to show all 12 months, otherwise we want to show months less than the current month. If I use the following:
CASE WHEN extract(month from current_date) = 1 THEN "Calculated Values Monthly"."MONTH" >= 1 ELSE "Calculated Values Monthly"."MONTH" < extract (month from current_date) END
I get the error below. All works fine until I add the CASE.
Error Codes: YQCO4T56:OPR4ONWY:U9IM8TAC:OI2DL65P
Location: saw.views.evc.activate, saw.httpserver.processrequest, saw.rpc.server.responder, saw.rpc.server, saw.rpc.server.handleConnection, saw.rpc.server.dispatch, saw.threadpool, saw.threadpool, saw.threads
Odbc driver returned an error (SQLExecDirectW).
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 27002] Near <>=>: Syntax error [nQSError: 26012] . (HY000)
Can you use a case statement in a filter? If not, what are the other options, if any?
ThxAccording to your requirements, when the month is January, you want all 12 months; any other number and you want months from 1 to "1 less than the current month number." Yes? Okay, here's what to do:
In the filter on your date column, click on the filter button, convert it to SQL and enter this:
MONTH(tablename.date_column) BETWEEN 1 AND CASE WHEN MONTH(CURRENT_DATE) = 1 THEN 12 ELSE MONTH(CURRENT_DATE)-1 END
Here's the logic:
a) When the current month is January, then the case statement will yield 12 and the filter will be:
WHERE MONTH(tablename.date_column) BETWEEN 1 AND 12 ...or all 12 months.
b) When the current month is any other month, say June, then the case statement will yield one less than the what the month number is, or in this case 5.
WHERE MONTH(tablename.date_column BETWEEN 1 AND 5 ...or all the months from 1 to 5 (Jan through May)
This will give you what you want...

Similar Messages

  • Case Statement alternative in answers...

    Hi All-
    we are using a case statement in one of the row fields in answers..The report is in pivot format.
    It is catching only the first statement and ignoring the second statement by printing '0'.
    The following is the case statement which we are using:
    case when
    "Fact"."Location" <> 'X'
    then
    (" Fact"."Service Revenue" / "Fact"."Hours Budget")
    else 
    "Fact"."Hourly Rate"
    end
    Hourly rate is the field in the existing table which we are using for the report.. the issue is it is ignoring to print this field when location = 'x'
    we have tried the filter function also but it is allowing only one filter statement.
    Could you please look into this?
    Thanks!
    Message was edited by: user13816768
    Message was edited by: user13816768

    Hi
    why cant u use the condition in RPD.
    In rpd use the case condition and make that as a one logical column. Test=" Fact"."Service Revenue" / "Fact"."Hours Budget". make it as a logical sum.
    Then bring this column in to answerside, and use the case condition
    case when
    "Fact"."Location" <> 'X'
    then
    (" Fact""Test")
    else 
    "Fact"."Hourly Rate"
    end
    Regards,
    VG

  • Pushing case statement applied in answers formula to Database

    Hi All,
    There are three prompts, for which there is a kind of header report with narrative view, now when user selects value in prompt element1 and do not select anything in prompt element 2 and 3, in the header only element1 should be displayed and emlement2,3 and few other elements should be nullified, to do this, i used presentation variables for element2,3 directly in narrative view. but for other non-prompt elements not to show up, i used case statement like:
    case when length(@{presntation_var}) > 0 then "display.column" else NULL end
    Now OBIEE is executing in such a way that, it is retrieving all the columns from the database and then applying logical case statement at BI server level, I need to push this case statement to DB level, can anyone help me how this could be accomplished.
    Thanks,
    Sreekanth Jala

    Hi
    why cant u use the condition in RPD.
    In rpd use the case condition and make that as a one logical column. Test=" Fact"."Service Revenue" / "Fact"."Hours Budget". make it as a logical sum.
    Then bring this column in to answerside, and use the case condition
    case when
    "Fact"."Location" <> 'X'
    then
    (" Fact""Test")
    else 
    "Fact"."Hourly Rate"
    end
    Regards,
    VG

  • Query Tuning - using CASE statement in the WHERE clause

    Hi All,
    My query has been modified to use a CASE statement in the WHERE clause to consider data from certain columns based on a parameter value. This modified query is doing a full table scan and running endlessly. Please suggest what may be done to improve its performance:
    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Table Description:
    (Number of rows : approx > 600,000,000)
    Name                           Null     Type      
    ARTICLEID                      NOT NULL NUMBER(20)
    USERKEY                                 NUMBER(10)
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE      
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10)
    LINENUMBER                              NUMBER(10)
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2) 
    REQUESTDATETIME                         VARCHAR2(19)Explain Plan
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2224314832
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    PLAN_TABLE_OUTPUT
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)Edited by: Chaitanya on Jun 9, 2011 2:44 AM
    Edited by: Chaitanya on Jun 9, 2011 2:47 AM

    Hi Dom,
    Modified Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    AND (('FULL'  = 'FULL'
    AND  (get_date_timestamp(os.requestdatetime)  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    AND   os.entry_CreatedDate BETWEEN TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    OR ('FULL'  = 'INCR'
    AND os.entry_createddate  BETWEEN TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
                   AND TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') ))
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;Execute Plan:
    PLAN_TABLE_OUTPUT
    Plan hash value: 3615447714
    | Id  | Operation                 | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT          |                   | 25125 |  1374K|       |   407K  (1)| 01:21:36 |       |       |
    |   1 |  HASH GROUP BY            |                   | 25125 |  1374K|  3768K|   407K  (1)| 01:21:36 |       |       |
    |   2 |   PARTITION RANGE ITERATOR|                   | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    |*  3 |    TABLE ACCESS FULL      | TABLE1 | 25125 |  1374K|       |   407K  (1)| 01:21:32 |    29 |    31 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter("OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  UPPER("OS"."SUCCESS_IND")='S' AND "OS"."REQUESTDATETIME" IS NOT NULL AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ACCTNUM" IS NOT NULL AND "OS"."AVIEWORIGIN_REFID" IS NOT NULL AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
                  2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))Edited by: Chaitanya on Jun 9, 2011 4:51 AM

  • Case statement in OWB mapping

    I am trying to use a case statement in an OWB mapping. I am attempting to use it in expression builder within a filter object. Each time I try to validate the expression in the expression builder I get an error:
    Line 4, Col 6:
    PL/SQL: ORA-00920: invalid relational operator
    Below is the code used in the expression builder window:
    CASE A.ATTRIBUTE_NAME
    WHEN 'CA COMPLETION DATE' THEN RTRIM(A.C_CODE_VALUE)
    ELSE NULL
    END
    Any help with what is happening would be appreciated.
    Thank you.
    Matt

    Thank you both for you help. I initially tried to use the expression operator but was confused since the expression builder in the expression operator has the drop down list with the available SQL clauses greyed out. In the OWB documentation it states that the drop down will contain SQL clauses that are appropriate for that expression type so when I saw it was greyed out I assumed that those clauses where not valid for this operator. Sure enough though when I pasted in my Case statement it verified correctly.
    Thanks again,
    Matt

  • Is it possible to use a case statement when joining different tables based on input parameters?

    Hi,
    I have a scenario where my stored procedure takes 5 parameters and the users can pass NULL or some value to these parameters and based on the parameters, I need to pull data from various tables.
    Is it possible to use a case statement in the join, similar the one in the below example. I'm getting error when I use the below type of statement.
    select a.*
    from a
    case
    when parameter1=1 then
    inner join a on a.id = b.id
    when parameter1=2 then
    inner join a on a.id = c.id
    end;
    Please let me know, if this type of statement works, and if it works will it create any performance issues?. If the above doesn't work, could you please give me some alternate solutions?
    Thanks.

    Here's a technique for joining A to B or C depending on the input parameters. In theory, you are joining to both tables but the execution plan includes filters to skip whichever join is not appropriate. The drawback is that you have to do outer joins, not inner ones.
    CREATE TABLE A AS SELECT LEVEL ak FROM dual CONNECT BY LEVEL <= 100;
    CREATE TABLE b AS SELECT ak, bk
    FROM A, (SELECT LEVEL bk FROM dual CONNECT BY LEVEL <= 10);
    CREATE TABLE c(ak, ck) AS SELECT ak, bk*10 FROM b;
    variable p1 NUMBER;
    variable p2 NUMBER;
    exec :p1 := 1;
    exec :p2 := 20;
    SELECT /*+ gather_plan_statistics */ A.ak, nvl(b.bk, c.ck) otherk FROM A
    LEFT JOIN b ON A.ak = b.ak AND :p1 IS NOT NULL AND b.bk = :p1
    LEFT JOIN c ON A.ak = c.ak AND :p1 is null and :p2 IS NOT NULL and c.ck = :p2
    WHERE A.ak <= 9;
    SELECT * FROM TABLE(dbms_xplan.display_cursor(NULL,NULL,'IOSTATS LAST'));
    | Id  | Operation             | Name            | Starts | E-Rows | A-Rows |   A-Time   | Buffers |
    |   0 | SELECT STATEMENT      |                 |      1 |        |      9 |00:00:00.01 |       7 |
    |*  1 |  HASH JOIN OUTER      |                 |      1 |      9 |      9 |00:00:00.01 |       7 |
    |*  2 |   HASH JOIN OUTER     |                 |      1 |      9 |      9 |00:00:00.01 |       7 |
    |*  3 |    TABLE ACCESS FULL  | A               |      1 |      9 |      9 |00:00:00.01 |       3 |
    |   4 |    VIEW               | VW_DCL_5532A50F |      1 |      9 |      9 |00:00:00.01 |       4 |
    |*  5 |     FILTER            |                 |      1 |        |      9 |00:00:00.01 |       4 |
    |*  6 |      TABLE ACCESS FULL| B               |      1 |      9 |      9 |00:00:00.01 |       4 |
    |   7 |   VIEW                | VW_DCL_5532A50F |      1 |      9 |      0 |00:00:00.01 |       0 |
    |*  8 |    FILTER             |                 |      1 |        |      0 |00:00:00.01 |       0 |
    |*  9 |     TABLE ACCESS FULL | C               |      0 |      9 |      0 |00:00:00.01 |       0 |
    Predicate Information (identified by operation id):
       1 - access("A"."AK"="ITEM_0")
       2 - access("A"."AK"="ITEM_1")
       3 - filter("A"."AK"<=9)
      5 - filter(:P1 IS NOT NULL)
       6 - filter(("B"."AK"<=9 AND "B"."BK"=:P1))
       8 - filter((:P2 IS NOT NULL AND :P1 IS NULL))
       9 - filter(("C"."AK"<=9 AND "C"."CK"=:P2))
    You can see that table C was not really accessed: the buffer count is 0.
    exec :p1 := NULL;
    SELECT /*+ gather_plan_statistics */ A.ak, nvl(b.bk, c.ck) otherk FROM A
    LEFT JOIN b ON A.ak = b.ak AND :p1 IS NOT NULL AND b.bk = :p1
    LEFT JOIN c ON A.ak = c.ak AND :p1 is null and :p2 IS NOT NULL and c.ck = :p2
    WHERE A.ak <= 9;
    SELECT * FROM TABLE(dbms_xplan.display_cursor(NULL,NULL,'IOSTATS LAST'));
    Now table B is not accessed.
    | Id  | Operation             | Name            | Starts | E-Rows | A-Rows |   A-Time   | Buffers | Reads  |
    |   0 | SELECT STATEMENT      |                 |      1 |        |      9 |00:00:00.02 |       7 |      2 |
    |*  1 |  HASH JOIN OUTER      |                 |      1 |      9 |      9 |00:00:00.02 |       7 |      2 |
    |*  2 |   HASH JOIN OUTER     |                 |      1 |      9 |      9 |00:00:00.01 |       3 |      0 |
    |*  3 |    TABLE ACCESS FULL  | A               |      1 |      9 |      9 |00:00:00.01 |       3 |      0 |
    |   4 |    VIEW               | VW_DCL_5532A50F |      1 |      9 |      0 |00:00:00.01 |       0 |      0 |
    |*  5 |     FILTER            |                 |      1 |        |      0 |00:00:00.01 |       0 |      0 |
    |*  6 |      TABLE ACCESS FULL| B               |      0 |      9 |      0 |00:00:00.01 |       0 |      0 |
    |   7 |   VIEW                | VW_DCL_5532A50F |      1 |      9 |      9 |00:00:00.01 |       4 |      2 |
    |*  8 |    FILTER             |                 |      1 |        |      9 |00:00:00.01 |       4 |      2 |
    |*  9 |     TABLE ACCESS FULL | C               |      1 |      9 |      9 |00:00:00.01 |       4 |      2 |

  • Issue with referencing Presentation variables(Date cols) in Case statement

    Hi,
    I m trying to reference presentation variables created on a Date column in the case statement of one of the request's columns as shown below:
    case when "- Quote Details"."Creation Date" between '@{from}{1999-1-1}' and '@{until}{2999-1-1}' then "- Quote Metrics"."# of Quotes" end
    I m getting a view display error with the below error message:
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1861, message: ORA-01861: literal does not match format string at OCI call OCIStmtExecute
    SQL Issued: SELECT "- Quote Types"."Level2 Name" saw_0, case when "- Quote Details"."Creation Date" between '4/1/2009' and '4/15/2009' then "- Quote Metrics"."# of Quotes" end saw_1 FROM "(Unity) Quotes Catalog" WHERE "- Quote Details"."Creation Date" BETWEEN timestamp '2009-04-01 00:00:00' AND timestamp '2009-04-15 00:00:00' ORDER BY saw_0
    When I created the prompt on the date field I put the following formula in the prompt:
    cast("- Time".Day as DATE)
    When I apply a filter on the request using these variables it works fine.
    If anyone has faced this kind of issue earlier and have a resolution, please help me out.
    Thanks,
    Kartik

    Thanks Goran!!
    I've created prompts by selecting columns from the logical tables (i.e. I've selected 2 different cols of datatype DATE...inorder to assign 2 presentation variables).
    Yes I m using calendar widget for prompts.
    I haven't included any filter in my report. I m trying to display a metric when it satisfies the case statement.
    I will defintley go through the blogs you mentioned for better understanding.
    Thanks,
    Kartik
    Query fired on physical db:
    WITH
    SAWITH0 AS (select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3,
    D1.c4 as c4,
    D1.c5 as c5
    from
    (select T192898.QLS_FIRST_ACAP_DT as c1,
    TO_DATE('3/2/2009','mm/dd/yyyy') as c2,
    TO_DATE('4/29/2009','mm/dd/yyyy') as c3,
    T188666.LEVEL2_NAME as c4,
    T188666.ID as c5,
    ROW_NUMBER() OVER (PARTITION BY T188666.ID, T192898.QLS_FIRST_ACAP_DT ORDER BY T188666.ID ASC, T192898.QLS_FIRST_ACAP_DT ASC) as c6
    from
    XXSLS_GBL_QTE_TYPES_V T188666,
    XXSLS_GBL_QTE_DTL_F T192898
    where ( T188666.ID = T192898.QUOTE_TYPE_ID )
    ) D1
    where ( D1.c6 = 1 ) ),
    SAWITH1 AS (select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3
    from
    (select count(distinct T192898.QUOTE_HEADER_ID) as c1,
    T188666.LEVEL2_NAME as c2,
    T188666.ID as c3,
    ROW_NUMBER() OVER (PARTITION BY T188666.ID ORDER BY T188666.ID ASC) as c4
    from
    XXSLS_GBL_QTE_TYPES_V T188666,
    XXSLS_GBL_QTE_DTL_F T192898
    where ( T188666.ID = T192898.QUOTE_TYPE_ID )
    group by T188666.ID, T188666.LEVEL2_NAME
    ) D1
    where ( D1.c4 = 1 ) ),
    SAWITH2 AS (select D1.c1 as c1,
    D1.c2 as c2,
    D1.c3 as c3
    from
    (select case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end as c1,
    case when SAWITH0.c1 between SAWITH0.c2 and SAWITH0.c3 then SAWITH1.c1 else NULL end as c2,
    case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end as c3,
    ROW_NUMBER() OVER (PARTITION BY case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end , case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end ORDER BY case when SAWITH0.c5 is not null then SAWITH0.c5 when SAWITH1.c3 is not null then SAWITH1.c3 end ASC, case when SAWITH1.c2 is not null then SAWITH1.c2 when SAWITH0.c4 is not null then SAWITH0.c4 end ASC) as c4
    from
    SAWITH0 full outer join SAWITH1 On SAWITH0.c5 = SAWITH1.c3
    ) D1
    where ( D1.c4 = 1 ) )
    select SAWITH2.c1 as c1,
    SAWITH2.c2 as c2
    from
    SAWITH2
    order by c1

  • Case statement to decode

    Hello,
    I am used to using case within my select statements, I need to use decode if possible for this one. Its for a record group within in forms, and the case statement is not working. Could someone please help me write this with decode instead of case?
    SELECT CASE
           WHEN months_between(sysdate , c.birth_dt) BETWEEN 168 AND 216 THEN 1 --14 to 18
           WHEN months_between(sysdate , c.birth_dt) BETWEEN 217 AND 252 THEN 2 --18 to 21
           WHEN months_between(sysdate , c.birth_dt) BETWEEN 253 AND 780 THEN 3 --21 to 65
           WHEN months_between(sysdate , c.birth_dt) > 780 then 4 --older than 65
           ELSE NULL END
    FROM mw_clients cThanks in advance!
    Jim P.

    Below solution is very easy to write.
    But I think that performance will be bad.Not really as dual is internal to the SQL engine so there's little difference between the two...
    SQL> ed
    Wrote file afiedt.buf
      1  with mw_clients as (select add_months(sysdate,-200) as birth_dt from dual union
      2                      select add_months(sysdate,-220) from dual union
      3                      select add_months(sysdate,-400) from dual)
      4  -- END OF TEST DATA
      5  select 4+
      6         decode(Least(months_between(sysdate , c.birth_dt),168),
      7                168,decode(greatest(months_between(sysdate , c.birth_dt),216),
      8                           216,-3,0)
      9                ,0)+
    10         decode(Least(months_between(sysdate , c.birth_dt),217),
    11                217,decode(greatest(months_between(sysdate , c.birth_dt),252),
    12                           252,-2,0)
    13                ,0)+
    14         decode(Least(months_between(sysdate , c.birth_dt),253),
    15                253,decode(greatest(months_between(sysdate , c.birth_dt),780),
    16                           780,-1,0)
    17                ,0) as result
    18* from mw_clients c
    SQL> /
        RESULT
             3
             2
             1
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 1277652150
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     3 |    27 |     9  (34)| 00:00:01 |
    |   1 |  VIEW            |      |     3 |    27 |     9  (34)| 00:00:01 |
    |   2 |   SORT UNIQUE    |      |     3 |       |     9  (78)| 00:00:01 |
    |   3 |    UNION-ALL     |      |       |       |            |          |
    |   4 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |   5 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |   6 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            456  bytes sent via SQL*Net to client
            396  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              1  sorts (memory)
              0  sorts (disk)
              3  rows processed
    SQL>
    SQL> ed
    Wrote file afiedt.buf
      1  with mw_clients as (select add_months(sysdate,-200) as birth_dt from dual union
      2                      select add_months(sysdate,-220) from dual union
      3                      select add_months(sysdate,-400) from dual)
      4  -- END OF TEST DATA
      5  select c.birth_dt,
      6         (select 1 from dual where months_between(sysdate , c.birth_dt) BETWEEN 168 AND 216 union
      7          select 2 from dual where months_between(sysdate , c.birth_dt) BETWEEN 217 AND 252 union
      8          select 3 from dual where months_between(sysdate , c.birth_dt) BETWEEN 253 AND 780 union
      9          select 4 from dual where months_between(sysdate , c.birth_dt) > 780
    10         ) as result
    11* from mw_clients c
    SQL> /
    BIRTH_DT                RESULT
    06/08/1974 10:15:39          3
    06/08/1989 10:15:39          2
    06/04/1991 10:15:39          1
    Elapsed: 00:00:00.01
    Execution Plan
    Plan hash value: 706016619
    | Id  | Operation        | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT |      |     3 |    27 |     9  (34)| 00:00:01 |
    |   1 |  SORT UNIQUE     |      |     4 |       |    12  (84)| 00:00:01 |
    |   2 |   UNION-ALL      |      |       |       |            |          |
    |*  3 |    FILTER        |      |       |       |            |          |
    |   4 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |*  5 |    FILTER        |      |       |       |            |          |
    |   6 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |*  7 |    FILTER        |      |       |       |            |          |
    |   8 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |*  9 |    FILTER        |      |       |       |            |          |
    |  10 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  11 |  VIEW            |      |     3 |    27 |     9  (34)| 00:00:01 |
    |  12 |   SORT UNIQUE    |      |     3 |       |     9  (78)| 00:00:01 |
    |  13 |    UNION-ALL     |      |       |       |            |          |
    |  14 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  15 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    |  16 |     FAST DUAL    |      |     1 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=216 AND
                  MONTHS_BETWEEN(SYSDATE@!,:B2)>=168)
       5 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=252 AND
                  MONTHS_BETWEEN(SYSDATE@!,:B2)>=217)
       7 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)<=780 AND
                  MONTHS_BETWEEN(SYSDATE@!,:B2)>=253)
       9 - filter(MONTHS_BETWEEN(SYSDATE@!,:B1)>780)
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            538  bytes sent via SQL*Net to client
            396  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              4  sorts (memory)
              0  sorts (disk)
              3  rows processed
    SQL> ed

  • SQL Query - case statement

    HI Friends ,
    My Scenario in table data :
    EmpId       fromdate           todate                Billtype
    2              01-09-2014        09-09-2014         B
    3              01-09-2014         NULL                   B
    2              10-09-2014        NULL                    P
    4             01-09-2014        NULL                     U
    5             01-09-2014        15-09-2014           B
    5             16-09-2014        30-09-2014            U
    OutPut :
    EmpId    Status
    2     P
    3     B
    4    U
    5    P
    requirement : Need to develop this Sql Query ..Using the Case statement .
    Please Help
    thanks
    Rakesh

    Wonderfull Patrick......
    I executed the logic and returning the expected result .  Thanks a lot.
    But still need some more modification ......
    suppose an employee E7 has the following entry :
    E7    01-04-2014      20-06-2014       B
    E7    21-06-2014      Null                   P
    This means that the Employee E7 has Joined Project P1 in April First  on a Billed Project and worked till July 20th and then again Moved to a Partial Billing Project P3 and from that July Till working in that Project
    So as per logic , we are suppose to get the Status of the Employees in the previous Month.....logically means October......  so for the same E7  the Status would  be "P"...because from July he is working on a Partial Billed Project
    .....   If suppose E7 worked on an Unbilled Project from July .... then for the month of October ......the Status for the same  E7 would be "U"
    Soooo ......if Employee E8 made 2 transitions within a month take example of last month October .
    E7    01-04-2014      20-06-2014        B
    E7    21-06-2014      Null                    P
    E8    01-10-2014      20-10-2014       B
    E8    21-10-2014      23-10-2014       P
    E8    24-10-2014      Null/Empty         U
    so for this employee the Result for the November month will be  "P" but if i check in month of december ...... for the same the satus should be "U" because from the last October 24th he is working on a "UnBilled Project"
    Please Help ......!!!
    I think what you need is just a filter like below
    declare @FromDate datetime
    SET @FromDate ='20141001'
    SELECT EmpId,
    CASE WHEN MAX(Billtype) = 'B' THEN 'B'
    WHEN MIN(Billtype) = 'U' THEN 'U'
    ELSE 'P'
    END AS Status
    FROM table
    WHERE fromdate >= @FromDate
    OR (fromdate < @Fromdate
    AND (todate > @FromDate
    OR todate IS NULL))
    GROUP BY EmpId
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Case statement performance

    Hello,
    This is relating to one of the previous posts.
    CASE STATEMENT PERFORMANCE
    As it has been a discussion of case statement performance. I tried to compare both the filter function and case statement.
    they both actually generate the same physical query.
    So I just am trying to understand the difference.
    thanks,
    Deep

    Hi Deep,
    There would be some performance using CASE where as filter function would generate straight SQL that is WHERE clause is added into the SQL statement for better performance.
    Have a look at this http://www.biconsultinggroup.com/obiee-tips-and-tricks/using-a-filter-function-instead-of-case-statements.html
    http://prolynxuk.com/blog/?p=462
    UPDATED POST
    Can you paste both SQL's generated here.
    hope answered
    Cheers,
    KK
    Edited by: Kranthi.K on Apr 22, 2011 7:33 PM

  • Case statement doubt

    Hi,
    I need some help with a simple case statement. lets say i have a table called name which has following 2 rows -
    ID first_name last_name
    1 JOHN SMITH
    2 JOHN
    i want to write a statement like :-
    select id,case when first_name like '%JO%' then 'John in first_name'
    when last_name like '%SM%' then 'Smith in last_name'
    end result from sample_table;
    The result displayed is -
    1 John in first_name
    2 John in first_name
    how can i rewrite this query to also include a 3rd row which will display the result as -
    1 John in first_name
    2 John in first_name
    1 Smith in last_name
    I want to display this 3rd row which displays last name also.
    Please help.

    974647 wrote:
    Hi,
    I need some help with a simple case statement. lets say i have a table called name which has following 2 rows -
    ID first_name last_name
    1 JOHN SMITH
    2 JOHN
    i want to write a statement like :-
    select id,case when first_name like '%JO%' then 'John in first_name'
    when last_name like '%SM%' then 'Smith in last_name'
    end result from sample_table;
    The result displayed is -
    1 John in first_name
    2 John in first_name
    how can i rewrite this query to also include a 3rd row which will display the result as -
    1 John in first_name
    2 John in first_name
    1 Smith in last_name
    I want to display this 3rd row which displays last name also.
    Please help.Hi,
    welcome to the forum.
    Please read SQL and PL/SQL FAQ
    Additionally when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    SELECT ...
    {noformat}{noformat}
    What you want to achieve cannot be done with a single query without using some tricks.
    Let's start from the point that your table has 2 rows. If you make a query without using a filter (A WHERE clause) and without using any CONNECT BY clause the number of rows returned by your query will be 2.
    So a possible solution is to make a union of the same table applying the condition to select only records that you want to display.
    i.e.:
    First I select only records having first_name like '%JO%' then I make a union with all rows having last_name like '%SM%'WITH sample_table AS
    SELECT 1 id, 'JOHN' first_name, 'SMITH' last_name FROM DUAL UNION ALL
    SELECT 2 id, 'JOHN' first_name, NULL last_name FROM DUAL
    SELECT id, 'John in first_name' txt
    FROM sample_table
    WHERE first_name like '%JO%'
    UNION ALL
    SELECT id, 'Smith in last_name' txt
    FROM sample_table
    WHERE last_name like '%SM%';
    ID TXT
    1 John in first_name
    2 John in first_name
    1 Smith in last_name
    Regards.
    Al
    Edited by: Alberto Faenza on Dec 3, 2012 5:27 PM
    Removed case, no need                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Case Statement and Sequential Count

    I would like to obtain user input via a prompt and use what the user selects in my OBIEE Report case statement. I ve done the parameter part with a presentation variable.
    and a filter with the following.
    Recv Date is between @{Repair_Start_Date}{01-01-2013} and @{Repair_End_Date}{01-01-2013}
    Now I would like to have a sequential count of the records that meet the case statement, please advise.
    For example &START_DATE AND &END_DATE are user inputs:
    CASE when SHIP_DATE BETWEEN &START_DATE AND &END_DATE THEN 1
    Thanks

    Hi,
    Here is a way you could try.
    CASE when SHIP_DATE BETWEEN &START_DATE AND &END_DATE THEN RSUM(1) END
    So, what it does?
    Whenever the CASE statement is satisfied, it increments 1 by 1.
    Hope this helps.
    Thank you,
    Dhar

  • Need help to write case statement

    Hi Guys,
    I have dashboard in which its has pprompt called PROPMT1 in that prompt it has three values A,B,C
    but iwant the full abbreviation of those values like A=APPLE B=BOY and C=Cindy
    and also in the report i have the coloumn is prompted by PROMPT1 which has again A,B,C values that need to be modified as A=APPLE B=BOY and C=Cindy
    how can i do it with case statement.

    For the prompt, write this in the Show window>SQL Results:
    1) CASE WHEN 1=0 THEN char_columnname ELSE 'A = APPLE' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'B = BOY' END FROM "your subject area" UNION ALL CASE WHEN 1=0 THEN char_columnname ELSE 'C = Cindy' END FROM "your subject area"
    2) Save the prompt to a presentation variable, pv_choice
    This will give you your three values. Make sure you use a CHAR column, doesnt matter what column, though.
    For the report,
    1) Create a BINS column on the column that contains the A, B, C values and make the BINS A = APPLE, B = BOY, C = Cindy just like the prompt values.
    2) Now put a filter on this BINS column and set it equal to your pv_choice presentation variable.
    That's it.
    NOTE: Obviously, if you want the prompt values to just say "APPLE," "BOY," and "Cindy," then take off the 'A = ', 'B = ' and 'C = ' appropriately. Same for the BINS in your report.
    Edited by: David_T on Jun 8, 2011 10:57 AM

  • SQL Expression in decode function or case statement?

    Can I put SQL expressions in decode function or case statement?
    For example,
    select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
    from element le;
    or
    select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
    ELSE 'Y'
    from element le;
    None of the above work.
    Can anyone tell me how to make it work?
    Is there any workaround?
    Thanks,
    J

    You simply needed and END to your CASE statement;
    SQL> with profile_data as (
       select 'XXXX_AFTER' name, 1 object_id from dual),
         element as (
       select 1 profile from dual union all
       select 2 from dual)
    select le.profile,
       case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
       THEN 'N'
       ELSE 'Y'
       END new_col
    from element le
       PROFILE N
             1 Y
             2 N

  • CASE not found while executing CASE statement on Submit Form

    Hi to all APEX users and developers.
    I have several APEX applications and they are all working well, but recently I got one strange exception when I try to submit page:
    Session: Fetch session header information
    ...metadata, fetch page info
    ...Validate item page affinity.
    ...Validate hidden_protected items.
    Add error onto error stack
    ...Error data:
    ......message: Error processing request.
    ......additional_info: ORA-06592: CASE not found while executing CASE statement
    ......display_location: ON_ERROR_PAGE
    ......is_internal_error: true
    ......apex_error_code: APEX.UNHANDLED_ERROR
    ......ora_sqlcode: -6592
    ......ora_sqlerrm: ORA-06592: CASE not found while executing CASE statement
    .....error_backtrace: ORA-06512: at "APEX_040100.WWV_FLOW", line 9273
    ......component.type: APEX_APPLICATION_AUTH
    ......component.id: 41350431648668800
    ......component.name: MNRFR
    ...Show Error on Error Page
    ......Performing rollback
    Processes - point: AFTER_ERROR_HEADER
    Processes - point: BEFORE_ERROR_FOOTER
    End Page Processinga
    Page has more than 120 items (most of them are hidden), so my first thought is that page has problem with posting so many items, but APEX error message doesn't hel me at all. Any help would be very appreciated :)
    Almir

    Hi Almir,
    actually it is the 100 page item limit. See (http://download.oracle.com/docs/cd/E17556_01/doc/user.40/e15517/limits.htm)
    I also had a look into the source code and the code at the position where the error gets raised only supports 100 page items.
    Can you have a look into the generated HTML code and look if you have a page items which is mapped to p_t101 or a higher number ?
    I will file a bug to show a better error message.
    Regards
    Patrick
    My Blog: http://www.inside-oracle-apex.com
    APEX Plug-Ins: http://apex.oracle.com/plugins
    Twitter: http://www.twitter.com/patrickwolf

Maybe you are looking for

  • Convert string to float

    It seems extremely rudimentary but I haven't been able to find an answer yet. I would like to pass in a string representing a human-readable floating point (ie, non IEEE 754) and get its value. A straight up assignment of a string variable into a f v

  • ITunes 10.4 display bug

    The latest version has a display problem. I regularly use a large external monitor with my MacBook, both 19 and 22 inch displays, often set vertically with display output rotated 90 degrees to give large full-page document editing. If i open iTunes i

  • Upgrading to 903 production: junit issue (+ solution)

    I couldn't find this in the release / install documentation so I thought I'd post it here. I upgraded from 903 preview to 903 production, migrated my earlier settings using "jdev -migrate" and then tried to compile one of my projects. The compilation

  • Creating motion menus for DVDSP

    Does anyone know of a good book or video (online is fine too) that really goes into the hows of creating moving menus in Motion to be used in DVDSP?

  • Bursting issue

    Hi All, I am using bursting for spliting the files and filenames. I am able to schdule a job with bursting successfully if it is single file. When there are multpile files to split it throws the below error, BIp v is 11g ::RIPPLE_OUTPUT_FAILED::[INST