Case when question

Hi All,
Is it possible to use case-when statement in this SQL query?
select SUB_ID, count(T_ID),sum(TIME)
from TABLE_A
where SUB_ID <> ' '
and STARTDATE between :P6_DATE_FROM and :P6_DATE_TO
CASE :P6_FILTER_BY
WHEN '1' THEN 'and SUB_ID like :P6_FILTER_BY_TEXT || ''@%'' '
WHEN '2' THEN 'having sum(TIME) >= :P6_FILTER_BY_TEXT '
END
group by SUB_ID
as it is it seems not to work...
thanks
Liron

Hi,
Is it possible to use case-when statement in this SQL query?Yes
First of all you are using the wrong syntax of CASE.
The correct syntax is :
   CASE
        WHEN var1 = 1  THEN
                   'One'
        WHEN var 2 = 2 THEN
             'Two'
     ELSE
        'Three'
     ENDTell us your requirement we might suggest something ?
Regards

Similar Messages

  • 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

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

  • Another case when statement

    Hi, another case statement question. My set up is calling from dasnboard prompt to publisher with an rtf template. My question is whether my logic/syntax is corrected. Thank you.
    and "office"."branch" = ( CASE WHEN :BRANCH = '' THEN "office"."branch" ELSE :BRANCH END)
    case when :BRANCH is null THEN 'or' ELSE 'and' END -----> (here I want to be able either or / and in case when edit box with BRANCH parameter is null use OR operator and when BRANCH parameter is field use AND operator.
    and "office"."employee" like upper( CASE WHEN :EMPLOYEE = '' THEN "office"."employee" ELSE :EMPLOYEE END)

    try this in TOAD (replace each apostrophe of your sql by two apostrophes and add the starting and ending apostrophe to obtain a string)
    execute immediate 'INSERT INTO DATAMART.PERSONSITE (PERSON_DBID,SITE) SELECT PDBIDSKILL.DBID, MIN(PDBIDSKILL.SKILL) FROM
    (SELECT DISTINCT DATAMART.V_CFG_PERSON.DBID, CASE WHEN DATAMART.V_CFG_SKILL.NAME=''Complex_Rslve'' OR DATAMART.V_CFG_SKILL.NAME=''Broadband_Business_Resolve'' THEN ''BBHD'' WHEN DATAMART.V_CFG_SKILL.NAME=''General'' OR DATAMART.V_CFG_SKILL.NAME=''General_Mobile'' OR DATAMART.V_CFG_SKILL.NAME=''General_Billing'' THEN ''MASS'' WHEN DATAMART.V_CFG_SKILL.NAME=''Faults_General'' OR DATAMART.V_CFG_SKILL.NAME=''Faults_Business'' THEN ''Faults'' ELSE ''_Other'' END AS SKILL
    FROM DATAMART.V_CFG_SKILL INNER JOIN DATAMART.V_CFG_SKILL_LEVEL ON DATAMART.V_CFG_SKILL.DBID = DATAMART.V_CFG_SKILL_LEVEL.SKILL_DBID
    INNER JOIN DATAMART.V_CFG_PERSON ON DATAMART.V_CFG_PERSON.DBID = DATAMART.V_CFG_SKILL_LEVEL.PERSON_DBID) PDBIDSKILL GROUP BY PDBIDSKILL.DBID';it should give the same result as your original sql statement
    before using the string in VBA you must replace '' with the characters used to denote an apostrophe within apostrophes.
    I don't know nothing about VBA but I'm sure you'll know how to deal with it (an apostrophe within apostrophes).
    Regards
    Etbin

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

  • CASE WHEN THEN END

    Hello everyone,
    We have a function return Y or N.
    We have 2 table YTable YT and NTable NT.
    We are using UNION now.
    SELECT ONE.CL1
    FROM (
    SELECT CL1Y FROM YTable WHERE FUNCTION = 'Y'
    UNION
    SELECT CL1N FROM NTable WHERE FUNCTION = 'N') ONEWe are wondering to use CASE, WHEN, THEN, END.
    Is it possible or NOT?
    If you have a chance, please share your experiences.
    Thanks in advance,
    NY
    P.S.
    If you have more questions, please let us know.
    Edited by: New Yorker on Aug 31, 2010 10:08 AM

    New Yorker,
    According to the given SQL block, the case function can not be used. You can use the case function with multiple table joins but you can only use the CASE WHEN ELSE END block for one column.
    If i got your question correct, that is my answer to your question.
    Regards.
    Ogan

  • Case when Query in SSRS

    I just want to post another new question based on last week's thread:
    Visakh16 provided me answer to use "CASE When" to handling different regions (see the Select statement below).
    My new question is:  I do need to add a new condition for transaction type = "Billing" after Case when Customer PO In ('12345', '3334444', '23434343'.  These 2 conditions need to be embedded in the region called as
    "America-Hub".
    For the rest of the regions (regions other than America-Hub), I need to filter transaction type = 'Booking".  So How can I combine the above new conditions into One query.
    Please help
    SELECT other columns...,
    CASE WHEN CustomerPO IN ('123456',
    '3343434', '2343434')
    THEN 'AMERICAS (Hub)'
    ELSE RegionFieldHere
    END AS Region
    FROM ...
    Thanks,
    Josephine
    Josey Tang

    Thanks for your reply yesterday.  I think I would like to clarify my requirement.  Below is the table that I expect to see from the query.  Customer PO # 123456', '3343434', '2343434' have 2 transaction types (Billing and Booking, please see BOLD
    sections below) so I do need to list out these 3 POs in "Booking" transaction type as well under "America" region.
    The region called it as "America-Hub" which does not exist, I do need to name this region manually (after filter out by these POs '123456', '3343434', '2343434' and filter by Transaction Type = "Billing"). 
    In the query output, I do need to list out all other customer POs for different regions such as "Japan", "Malaysia', etc.  (See purple section) for "Transaction Type" = Booking
    Below is the final data output that I expect to see in my query. Appreciate if you can help me out.
    Transaction   Type
    Region
    Customer PO
    Billing
    America-Hub
    123456
    Billing
    America-Hub
    3343434
    Billing
    America-Hub
    2343434
    Booking
    Japan
    8898989
    Booking
    Malaysia
    7783838
    Booking
    America
    123456
    Booking
    America
    3343434
    Booking
    America
    2343434
    Thanks,
    Josephine
    Josey Tang

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

  • "CASE WHEN 1=0 THEN.......ELSE....END"??

    This might be very basic question still I'm confused about it.
    Can you please explain me "CASE WHEN 1=0 THEN.......ELSE....END"?
    Where and why to use this statement??
    Help appreciated.

    First let's break down what it means. Since 1 is never equal to 0, OBI will ignore what comes immediately after and execute what comes after the ELSE.
    So why would we want to do this? Well, often we want to perform some action that has nothing to do with a particular column in our subject area. By using this CASE statement, we trick OBI into thinking we are using a column for a calculation or action, but in effect, the column is unchanged.
    For example, suppose you were building a dashboard prompt. You want to use a column twice in your dashboard prompt, say an ACCOUNT_OPEN_DATE column to get a range of dates. You cannot use the same column twice in a dashboard prompt. (Try it, OBI will ignore your attempt to put the same column twice into your workspace.)
    So what do you do? First you get a column (in this example, I'm using a CHAR column) like Branch Name. It doesn't matter what column you use. The CHAR is used so the syntax makes sense.
    You move the column to your workspace. Now you click on the Edit Formula and you type CASE WHEN 1=0 THEN Organization."Branch Name" ELSE 'TEST' END.
    So in this case, the values of Branch Name are unaffected and the dummy column just represents the word 'TEST.' Now in the "Show" part of the prompt, we switch to "SQL Results" and type SELECT "Account Attributes".Account_Open_Date FROM Subject Area and set this to a PV called StartDate.
    Because the column is a dummy, you can actually call it again. Use the same CASE statement to make it a "dummy" column. Then use the same SQL you used above, but this time save it to a PV called EndDate.
    Now you have two date values you can use on your ACCOUNT_OPEN_DATE column to get a range of dates.
    So, in conclusion, normally you choose a column from your subject area, because you need the values of that column in your report. But when you just need a column to do something unrelated to any column, you use the CASE 1=0 to make it a "dummy" column and then you can perform your action.
    HTH,

  • About case when and the sql clause

    Hi:
    The following is my sql clause:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%' AND b.name like '%'||:name||'%'
    ORDER BY t.ChineseName
    The main problem is I hope to check the b.name if it is null it can be passed as NVL function, so I try using case when, but it not working.
    When b.name exist in where clause, the result columns will not include the data without b.name(or implies the b.name is NULL); And that
    make the result data not exactly right.
    is it possible to use case when to make the following snippet implemented:
    case when b.name is not NULL then b.name like '%'||:name||'%'
    else b.name = NULL(b.name=b.name seems not work to parsing null data)
    end
    Thanks a lot.

    962769 wrote:
    Hi:
    The following is my sql clause:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%' AND b.name like '%'||:name||'%'
    ORDER BY t.ChineseName
    The main problem is I hope to check the b.name if it is null it can be passed as NVL function, so I try using case when, but it not working.
    When b.name exist in where clause, the result columns will not include the data without b.name(or implies the b.name is NULL); And that
    make the result data not exactly right.
    is it possible to use case when to make the following snippet implemented:
    case when b.name is not NULL then b.name like '%'||:name||'%'
    else b.name = NULL(b.name=b.name seems not work to parsing null data)
    end
    Thanks a lot.Your question isn't very clear. But below is the statement as I make a meaning out of it.
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%'
         AND b.name like '%'||NVL(:name, b.name)||'%'
    ORDER BY t.ChineseNameIf you want to use case, then:
    SELECT t.*,b.name
    FROM dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '%'||:ChineseName||'%'
         AND b.name like '%'|| case when b.name is not null then :name else b.name end ||'%'
    ORDER BY t.ChineseNameIf this is not what you are looking for then, read {message:id=9360002} and post the relevant details with an example (Create Table script, Sample Data creation script and the Expected output of the sample data).

  • CASE WHEN syntax error - Dreamweaver MX

    Hi Gurus,
    I am trying to use the statement in the Recordset creator tool Advanced Mode:
    select PayDay,
    case when getdate() > PayDay
    then 'Out of Time'
    Else 'On Time'
    End
    From tPayment
    But I get the error:
    Microsoft OLE DB Provider for ODBC Drivers erro '80040e14'
    [Microsoft][Driver ODBC Microsoft Access] Syntax error (Operator missing).
    Anyone help me, please!
    Thanks is advance.

    Hi bregent,
    Thank you very much for your response.
    1) Tell us which verison of Access you are using
    - I am using Access 2007
    2) Use the app dev forum for these questions
    - I couldn't find this forum here
    3)  I didn't think Access supported CASE statements outside of VBA.
    - If there insn't, could be any other workable instead this one
    4) I've never seen CASE/WHEN. Can you refer me to documentation that supports this syntax?
    - I use case/when on MSSQL, I need one that works with Dreamweaver in the recorset creator. What can I use to know if:
    Today is greater than PayDay in the tPayment table then It is must tell me that it is Out of Time (case when getdate() > PayDay then 'Out of Time')
    If the PayDay in the tPayment table is greater than today then it must tell me that it is is On Time (Else'On Time' End).
    That is what I am looking for.
    Thanks a lot!

  • Using cfif v/s CASE WHEN

    Hi everyone,
    I'm currently working on optimizing a report that takes about
    2 minutes to load. The main reason is that it has sooo much data. I
    noticed 2 things that i might be able to improve on...first there
    are a ton of <cfif> statements and second there are so many
    Query of Queries for each record. Basically I need help with these
    2 things:
    1) There are quite a few boolean fields. Currently the logic
    is on the .cfm page meaning for a certain boolean field, we use
    <cfif qryGetPipelines.pipebdw_is_me_tech_assistance eq
    1>
    Y
    <cfelse>
    N
    </cfif>
    My question is that would it better and more efficient if i
    just use a CASE WHEN pipebdw_is_me_tech_assistance = 1
    THEN....statement in the query and that way i don't have to do the
    <cfif> on the .cfm page?
    2) My second question is: let's say the report pulls up 400
    records, i then loop through those records and display the
    different fields and i also perform about 10 Query of Queries in
    each loop to get fields that have more then 1 record. So bascially,
    for each of the 400 records, i have 10 additional Query of Queries
    and though it's only about 15 - 20 ms per query...when you add
    multiply 10 * 400 it takes up quite a lot of time. Is there any
    other way around this??
    Thank you so much for all your help.
    Anju

    @Ian - Thanks for your help Ian and the answer to your
    question is yes i do plan to put the CASE statement in the Sql
    query, currently the logic is being done by using <cfif> on
    the .cfm page.
    @Dan - Thanks for your help as well. Can you please give me a
    little more info as to what would be a more effiicient way then
    looping through a query in order for me to display about 30 columns
    (fields) of data for anywhere from 400 - 1000 records?
    Thanks again for all your help

  • Remove iPhone from case when charging?

    Ok, this may be a dumb question, but I would rather post a dumb question than really mess up. Once I read somewhere to take my iPod out of its case when I charge it, I guess it keeps it from getting too hot or something. My question is, should I take the iPhone out of its case (Marware leather flip vue) when I charge it, either at home or in the car?
    Many thanks in advance.
    Jan3

    The iPhone does not get particularly warm when charging, so it shouldn't normally be necessary to remove it from the case. If you're in an already-warm environment (e.g. a hot car) it's probably not a bad idea, though. High heat is bad for fully-charged batteries.
    Hope this helps...

  • I can't make movie, case when i try do it all time paw disappear-

    I can't make movie, case when i try do it all time paw disappear and i can't drag over part of video than when i try do that again part of video drag over in the place where must be the following piece and remains at this place as I did not change screen and it did not switch the window....  Halp me.

    Apple - Support - Mac Apps - iMovie
    If the linked Support articles do not help you, the video tutorials below may:
    Apple Tutorial Videos
    If you are still having trouble, try to ask your question in different words
    or post it in your native language.  Someone here may be able to help you.
    Message was edited by: EZ Jim
    Mac OSX 10.8.5

Maybe you are looking for