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

Similar Messages

  • Equivlent CASE WHEN query for Oracle 8.05

    Is there a way to construct a query similar to the statement below in Oracle version 8.05?
    SELECT ename, CASE WHEN empid>10000 THEN 'Old Timer' ELSE 'New Comer' END
    FROM employees;
    I would like to use a single select query to handle such situations. Thanks for any suggestions.
    Roger

    sql>select empid,
      2         decode(sign(10001 - empid), 1, 'Newcomer', 'Oldtimer') description
      3    from foo
      4   order by empid;
        EMPID DESCRIPT
         9999 Newcomer
        10000 Newcomer
        10001 Oldtimer
        10002 Oldtimer

  • Where case when query not running at all in 11.2.0.3

    Hi,
    I have a query that was running fine till the time we were in 11.1.0.7. Last month, we had a migration to 11.2.0.3, and the query has stopped running since then. It runs indefinitely, and finally I have to kill it. However, until 11.1.0.7, I had absolutely no problems with it. Not sure what changed in 11.2.0.3 that causes it to never give me a result. The query is as below:
    SELECT T1.NAME,T2.AGE,T2.level, T2.AMT,
    FROM table1 T1, table2 T2
    WHERE (CASE WHEN
    (T1.name = 'Peter' AND SUBSTR(T1.desc,1,15)=SUBSTR(T2.description,1,15))
    THEN 1
    ELSE 0
    END)=1;
    Please advise!
    Thanks in advance.

    Hi,
    CrazyAnie wrote:
    Hi,
    I have a query that was running fine till the time we were in 11.1.0.7. Last month, we had a migration to 11.2.0.3, and the query has stopped running since then. It runs indefinitely, and finally I have to kill it. However, until 11.1.0.7, I had absolutely no problems with it. Not sure what changed in 11.2.0.3 that causes it to never give me a result. The query is as below:
    SELECT T1.NAME,T2.AGE,T2.level, T2.AMT,
    FROM table1 T1, table2 T2
    WHERE (CASE WHEN
    (T1.name = 'Peter' AND SUBSTR(T1.desc,1,15)=SUBSTR(T2.description,1,15))
    THEN 1
    ELSE 0
    END)=1;
    Please advise!I'm surprised it runs in any version. You have a comma right before the keyword FROM. If you were not getting a compile-time error, that was a bug in 11.1.0.7 that they fixed by 11.2.0.3.
    It's still strange that the query runs for a long time. I would expect it to give you an error when you tried to compile it. Is there any chance that what you posted is not what you're actually running?
    Also, LEVEL, NAME and DESC are not good column names. How Oracle reacts to using keywords like that as column names can vary from version to version. If a word is in v$reserved_words.keyword, then it's best to avoid using it as a column (or table, or variable, or schema) name.
    Edited by: Frank Kulash on Nov 21, 2012 1:33 PM
    By the way, that WHERE clause is a lot more complicated than it needs to be. Why not use
    WHERE      t1.name = 'Peter'
    AND      SUBSTR ( t1."DESC"     -- If you must use DESC, double-quote it
                , 1
                , 15
                ) = SUBSTR ( t2.description
                               , 1
                     , 15
                     )? Always think carefully before using CASE in a WHERE (or HAVING, or START WITH, or CONNECT BY) clause.

  • Ssrs 2008 the report instead of showing Emp # want to show Emp Name , how i can write case when syntax

    working on SSRS report , pulling the data with Emp # I want to show with emp Name instead,
    is there way to write case when syntax so it can show only emp name instead of emp #
    for example
    Emp #        Emp Name
    144                 Kevin
    want report to pick the name as Kevin instead of 144
    any help will be great
    thansk

    thanks for reply RSingh
    I tried changing the query as you suggested
    SELECT [EMP #], [EMP NAME], FIELD1, FIELD2 FROM TABLENAME
    it did not work,  getting error message
    empLid  table name JMGPAYEMPLOYEE  and there is no emp name field
    when I modify the query as per above getting error message
    because I have 2 data set
    1.  Projid
    2. Projgroupid
    3.  parameter I have date
    below is my query
    SELECT        PROJTABLE.PROJID, PROJTABLE.PROJGROUPID, PROJTABLE.DATAAREAID, JMGPAYEMPLOYEE.EMPLID, PROJTRANSPOSTING.QTY, JMGPAYEMPLOYEE.PRICE,
                             PROJTABLE.DIMENSION2_, PROJTRANSPOSTING.POSTINGTYPE, PROJTRANSPOSTING.COSTSALES, PROJTRANSPOSTING.PROJTRANSDATE,
                             CATEGORYTABLE.CATEGORYNAME
    FROM            PROJTABLE INNER JOIN
                             PROJTRANSPOSTING ON PROJTABLE.PROJID = PROJTRANSPOSTING.PROJID AND PROJTABLE.DATAAREAID = PROJTRANSPOSTING.DATAAREAID
    INNER JOIN
                             JMGPAYEMPLOYEE ON PROJTRANSPOSTING.DATAAREAID = JMGPAYEMPLOYEE.DATAAREAID AND
                             PROJTRANSPOSTING.EMPLITEMID = JMGPAYEMPLOYEE.EMPLID INNER JOIN
                             CATEGORYTABLE ON JMGPAYEMPLOYEE.DATAAREAID = CATEGORYTABLE.DATAAREAID AND
                             JMGPAYEMPLOYEE.EMPLID = CATEGORYTABLE.CATEGORYID
    WHERE        (PROJTRANSPOSTING.COSTSALES = 1) AND (PROJTRANSPOSTING.POSTINGTYPE = 121) AND (PROJTRANSPOSTING.PROJTRANSDATE >= @Paramfromdate) AND
                             (PROJTRANSPOSTING.PROJTRANSDATE <= @ParamTodate)
    any advise will be helpful
    thanks

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

  • Difference of sql query in SQL Workshop and SQL Report (case when sum(...

    Hi ,
    I need some help, pls.
    The follwg report runs in SQL Workshop - but gives errors in the sql-query report in HTMLDB:
    SQL-Workshop:
    select
    case
    when SUM(S.POTENTIAL_GROWTH)> 1 and SUM(S.POTENTIAL_GROWTH) < 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)> 4 and SUM(S.POTENTIAL_GROWTH) < 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)> 8 and SUM(S.POTENTIAL_GROWTH) < 12 then 'Very Good'
    else 'too much'
    end
    from "SEGMENTATION" S
    In an HTMLDB SQL-Query Report I added Aliases (as requested for HTML) but still gives the error:
    <<Query cannot be parsed, please check the syntax of your query. (ORA-00920: invalid relational operator) >>
    the code:
    select
    case
    when SUM(S.POTENTIAL_GROWTH) pot_growth > 1 and SUM(S.POTENTIAL_GROWTH)pot_growth < 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)pot_growth > 4 and SUM(S.POTENTIAL_GROWTH)pot_growth < 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)pot_growth > 8 and SUM(S.POTENTIAL_GROWTH)pot_growth < 12 then 'Very Good'
    else 'too much'
    end
    from "SEGMENTATION" S
    any halp from the gurus wud be very much appreciated.
    TIA
    Bernhard

    Still you did not give the alias for the case when column. For that only you should give the alias
    select
    case
    when SUM(S.POTENTIAL_GROWTH) pot_growth &gt; 1 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 4 then 'Ok'
    when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 4 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 8 then 'SoSo'
    when SUM(S.POTENTIAL_GROWTH)pot_growth &gt; 8 and SUM(S.POTENTIAL_GROWTH)pot_growth &lt; 12 then 'Very Good'
    else 'too much'
    end "GROWTH"
    from "SEGMENTATION" S

  • Issue with case when try to modify the siimple query

    Hello PL/SQL Gurus/Experts,
    I am stuck with an issue (could be simple) but not gettings any headsway -
    select 365/day_num_yr Anul_Fact from Date where date_dt = trunc(sysdate -1) value returns is as - 1.46
    need to write this in the form of case (as i need to multiply this to some other outer query), i want to store it ina variable and and then use the same in outer one -
    but when use the following then it is always returning the value as 0 and not the same output as returned by the above query without case.
    select (case when date_dt =trunc(sysdate -1) then 365/day_num_yr else 0 END) Anul_Fact Kindly help, i appericate your time and effort in advance.

    Thanks for providing the Drop table and CTAS script. It eased the job of creating sample data;
    I only used few data from the table:
    drop table T4;
    create table T4(day_num_yr, date_dt) as
    select 249, to_date('09/05/2012', 'MM/DD/YYYY') from dual union all
    select 250, to_date('09/06/2012', 'MM/DD/YYYY') from dual union all
    select 251, to_date('09/07/2012', 'MM/DD/YYYY') from dual union all
    select 252, to_date('09/08/2012', 'MM/DD/YYYY') from dual;
    select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,
           case when date_dt = trunc(sysdate - 1) then 365 / day_num_yr
                else 0
           end num_day
      from t4;
    DATE_DT                   PREV_DT                   TRUNC_PREV_DT             NUM_DAY               
    05-SEP-12                 06-SEP-12                 06-SEP-12                 0                     
    06-SEP-12                 06-SEP-12                 06-SEP-12                 1.46                  
    07-SEP-12                 06-SEP-12                 06-SEP-12                 0                     
    08-SEP-12                 06-SEP-12                 06-SEP-12                 0See the output. For Date_DT as 6-Sep, i.e. a Day before Today, we are getting the Output, but for other dates we are not.
    One another suggestion I would like to make is, (assuming) you are using the Table only for storing the Current day of Year and not including Public Holidays etc. then you can use a 'DDD' format model to get the Current Day of year starting 1 Jan.
    Something like below:
    select date_dt, sysdate - 1 prev_dt, trunc(sysdate - 1) trunc_prev_dt,
           case when date_dt = trunc(sysdate - 1) then 365 / to_char(date_dt, 'DDD')
                else 0
           end num_day
      from t4;

  • CASE WHEN functionality in BI Publisher

    I have previously used Discoverer to do our reporting and am investigating the differences between the two products. I understand that its chalk and cheese but one thing I am having trouble identifying is the CASE WHEN functionality that we use Discoverer in BI Publisher.
    An example of the usage for our CASE WHEN would be creating a derived column in a report to convert existing data into a more standardised format.
    I imagine this is quite a simple answer and I have just missed it but could anyone out there help me with where I can input the functionality in BI publisher.
    I am not the most technically gifted so any answers with simple words help :-)
    Edited by: 943098 on 27-Jun-2012 03:25

    You can use CASE WHEN in a sql query in a data model. You can also use it in the RTF template via "if then else", choose statements etc
    Take a look at section 4.10 in the BI publisher Report Designer's guide for use cases/examples: http://docs.oracle.com/cd/E23943_01/bi.1111/e22254.pdf
    Thanks,
    Bipuser

  • Using CASE WHEN THEN in dynamic Region Source area

    Hi all,
    I've been knocking my head around on this one for a while. Hope someone can show me some guidance. So far, the SQL Query in the Region Source works ok except after the THEN ''||'LINK'||'' . All text between the single quotes displays, and not just the hyperlink LINK. (My goal is to this simple test working, then go back an substitute in APP_ID, Page#, SESSION variables.) But I'm stuck with this problem. Searched the forum but this is as far as I got. Below is the code I'm using in the Region Source area. Perhaps a region attribute setting is needed but I'm unsure. Thanks for any assistance. -Mike
    select DISTINCT
        AWARD,
        CASE
        WHEN WINNER_NAME = 'India Retail Support Team'
       THEN '<A HREF="http://www.hotmail.com">'||'LINK'||'</A>'         *----------------HREF link (LINK) is working fine here but doesn't work ok in Region Source.
        ELSE WINNER_NAME
        END WN,
            GBU_WINNER,
            DORDER
    from   GBUSERVICEPACESETTERAWARDS
    where FY = '2012'
    and TYPE = 'Service Award'

    >
    As previously requested, please update your forum profile with a real handle instead of "user10734329".
    I've been knocking my head around on this one for a while. Hope someone can show me some guidance. So far, the SQL Query in the Region Source works ok except after the THEN ''||'LINK'||'' . All text between the single quotes displays, and not just the hyperlink LINK.Not clear from this what the problem is. It appears to me that LINK is all of the "text between the single quotes". What do you mean by "all text"? (An example on apex.oracle.com is a good way to resolve such ambiguities...)
    The usual cause of unexpected results when the separation of concerns is breached and HTML is directly generated in report queries is having the Display Text As report column attribute wrongly set. Ensure it is Standard Report Column rather than the default Display as Text (escape special characters).

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

  • Count (case when) not working in sql

    Hi All,
    I am trying to find the count of members for a perticular date range, it seems not working correclty.
    Could any one help me out.
    here is the query...I am getting same output for all the cases..please help
    Select
    t
    .MemberNbr,t.patcom
    count(case
    when
    datediff(d,
    mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112))
    between
    -1
    and
    -365
    then t.MemberNbr
    else 0
    end)as
    edvisits365daysprior
    count(case
    when
    datediff(d,
    mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112))
    between 1
    and 3
    then t.MemberNbr
    else 0
    end)as
    edvisits3Days
    count(case
    when
    datediff(d,
    mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112))
    between 1
    and 30
    then t.MemberNbr
    else 0
    end)as
    edvisits30Days
    count(case
    when
    datediff(d,
    mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112))
    between 1
    and 60
    then t.MemberNbr
    else 0
    end)as
    edvisits60Days
    count(case
    when
    datediff(d,
    mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112))
    between 1
    and 90
    then t.MemberNbr
    else 0
    end)as
    edvisits90Days
    --,*--membernbr,specificdateofservice,count( membernbr)--, specificdateofservice)as visitcount--, patcom
    --Into #Tmp_PPCSEDCnt1
    From
    stg_tbl_InPatientPrepost Mbrs
    join
    #Tmp_MCCSEDVisits t
    on
    mbrs.MemberNbr=t.MemberNbr
    --where UPPER(t.MR_Line_Desc) in ('FOP EMERGENCY ROOM - HOSPITAL', 'FOP EMERGENCY ROOM Urgent Care',
    --'PROF ER VISITS AND OBSERVATION CARE')
    group
    by t.MemberNbr,t.patcom

    You may replace 0 as NULL and see how it works for you?
    eg:
    count(case when datediff(d, mbrs.DischargeDate,
    convert(datetime,convert(varchar(12),t.specificdateofservice),112)) 
    between -1 and -365 thent.MemberNbr else NULL end)as edvisits365daysprior

  • Receiving OCI/ORA-27163 when querying XML data in 11g.

    When querying a table with a column stored in XML format, we get this error for large XML values. This works in Oracle 10g but this error happens when the same data is queried in an 11.2.0.3 instance. I have had a support request open with Oracle for about a month and so far it has not made any progress. What we've seen are the following:
    1. The xml data itself is good.
    2. The good xml data when queried with a wholly 10g client/server environment, works.
    3. The same good xml data when inserted into a table in an 11g instance through a stored package run from the 11g instance (server to server) gets the 27163 error.
    4. The same xml data when queried in a 10g instance from an 11g client fails with the 27163 error.
    5. If we disable the 11g XML parser by setting an internal event (alter session set events='31156 trace name context forever, level 0x400';), then run the same code that was run in item 3 above, it does not get the 27163 error. However, the xml loaded to the 11g instance can then only be queried without getting the 27163 error if we use an older 10g client. An 11g client consistently gets the error.
    The server versions are 11.2.0.3 (upgraded from 10.2.0.4). The SQL*Net client versions that we have tested on are 11.2.0.2 and 11.2.0.3 (both produce the 27163 error).
    With considerable trial and error, we found that it is some combination of the file size and format that causes the error. Copied below is the smallest sample data of a failing XML that will produce this erro (about 8K). Remove any single character even in an a comment and the file parses successfully – but it’s not the file size alone as the original 800+KB file where we first dicovered this problem will process if the period in the attribute: @value=”${item.id}” is removed.
    We are at our wit's end, and with an 11g migration project looming, any ideas anyone can suggest would be very helpful.
    Thanks,
    Joe
    Here is a test case to play around with. Sorry I don't have a way to upload a zip file for this, but you can cut & paste from the post:
    1. CREATE TABLE my_xml_test
    (record_id NUMBER(4,0),
    xml SYS.XMLTYPE,
    comments VARCHAR2(200))
    ALTER TABLE my_xml_test
    ADD CONSTRAINT my_xml_test_pk PRIMARY KEY (record_id)
    USING INDEX
    2. mkdir SampleData
    3. cd into SampleData, copy the XML I will post in the first reply to this message into a new text document called xml_items_removed.xml.
    4. cd .. and create a file called 20120112_11g_bad_xml_issue.txt with this in it:
    1, .\SampleData\xml_items_removed.xml,"Fails: OriginalXML w/ all instances of <Item> removed (count 600) -- reduces file size to ca. 55KB but still fails (Saved by XMLSpy)"
    5. Next create your SQL*Loader control file (call it my_xml_test.ctl):
    LOAD DATA
    APPEND INTO TABLE my_xml_test
    FIELDS TERMINATED BY "," OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    record_id,
    ext_fname FILLER CHAR(200),
    xml LOBFILE(ext_fname) TERMINATED BY EOF,
    comments
    6. sqlldr <username>/<password>@<database> control=my_xml_test.ctl data=20120112_11g_bad_xml_issue.txt log=20120112_11g_bad_xml_issue.log bad=20120112_11g_bad_xml_issue.bad
    7. Once the data is loaded, query my_xml_test table that you created in step 1. You should get the 27163 error:
    SELECT a.record_id,
    comments,
    a.XML,
    length(a.XML.GetClobVal()) clob_length
    FROM my_xml_test a

    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XMLSpy v2012 sp1 (http://www.altova.com) by Martin l (National Board of Medical Examiners) -->
    <IRData application="Item Review" version="1.3" itempool="2006001" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <ViewerTypes>
              <Viewer id="its-viewer">
                   <Title>Item Text</Title>
                   <Description>Item Text</Description>
                   <BaseUrl>https://www.starttest.com/flex/4.3.0.0/InstitutionViewItem.aspx</BaseUrl>
                   <Parameters>
                        <Parameter name="pid" value="MSST"/>
                        <Parameter name="iid" value="01123"/>
                        <Parameter name="username" value="SomeUser"/>
                        <Parameter name="item" value="${item.id}"/>
                        <Parameter name="code" value="${CODE}"/>
                   </Parameters>
              </Viewer>
         </ViewerTypes>
         <Filters>
              <Filter id="drop-single-filter">
                   <AttributeSource>drop</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="onoff-single-filter">
                   <AttributeSource>onoff</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="reviewed-single-filter">
                   <AttributeSource>reviewed</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="build-multi-filter">
                   <AttributeSource>build</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="flag-multi-filter">
                   <AttributeSource>flag</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="u1dt-multi-filter">
                   <AttributeSource>U1DT</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="fb2-multi-filter">
                   <AttributeSource>FB2</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="fb1t-multi-filter">
                   <AttributeSource>FB1T</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="scorecat-multi-filter">
                   <AttributeSource>scorecat</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="images-multi-filter">
                   <AttributeSource>PIXN</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
              <Filter id="vignettes-multi-filter">
                   <AttributeSource>VIG1</AttributeSource>
                   <ControlType>select-1-drop-down-plus-all</ControlType>
              </Filter>
         </Filters>
         <DataPanels>
              <Control displayed="true">
                   <Filters>
                        <Filter>
                             <Description>Drop</Description>
                             <FilterSource>drop-single-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Version</Description>
                             <FilterSource>build-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>On/Off Test</Description>
                             <FilterSource>onoff-single-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Review status</Description>
                             <FilterSource>reviewed-single-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Flag</Description>
                             <FilterSource>flag-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Discipline</Description>
                             <FilterSource>fb1t-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Organ System</Description>
                             <FilterSource>u1dt-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Step 1 outline</Description>
                             <FilterSource>fb2-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Images</Description>
                             <FilterSource>images-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Vignettes</Description>
                             <FilterSource>vignettes-multi-filter</FilterSource>
                        </Filter>
                        <Filter>
                             <Description>Score categories</Description>
                             <FilterSource>scorecat-multi-filter</FilterSource>
                        </Filter>
                   </Filters>
              </Control>
              <ItemList displayed="true">
                   <Attributes>
                        <Attribute displayed="true">
                             <Description>Item</Description>
                             <AttributeSource>itemref</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>On test</Description>
                             <AttributeSource>onoff</AttributeSource>
                             <ControlType>checkbox-select</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Drop</Description>
                             <AttributeSource>drop</AttributeSource>
                             <ControlType>checkbox-select</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Reviewed</Description>
                             <AttributeSource>reviewed</AttributeSource>
                             <ControlType>check-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Flag</Description>
                             <AttributeSource>flag</AttributeSource>
                             <ControlType>select-1-drop-down</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Description</Description>
                             <AttributeSource>DESCR</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Discipline</Description>
                             <AttributeSource>FB1T</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Organ System</Description>
                             <AttributeSource>U1DT</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Step 1 outline</Description>
                             <AttributeSource>FB2</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <!-- Attribute displayed="false">                         <Description>Organ System plus</Description>                         <AttributeSource>ORGA</AttributeSource>                         <ControlType>text-display</ControlType>                    </Attribute -->
                        <Attribute displayed="true">
                             <Description>Images</Description>
                             <AttributeSource>PIXN</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Vignettes</Description>
                             <AttributeSource>VIG1</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Diff</Description>
                             <AttributeSource>pvalue</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Discr</Description>
                             <AttributeSource>rbvalue</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Answer Key</Description>
                             <AttributeSource>key</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                        <Attribute displayed="true">
                             <Description>Notes</Description>
                             <AttributeSource>notes</AttributeSource>
                             <ControlType>text-display</ControlType>
                        </Attribute>
                   </Attributes>
              </ItemList>
              <CurrentItemInfo>
                   <ItemText displayed="true"/>
                   <ItemData>
                        <Attribute>
                             <DataSource>scorecat</DataSource>
                             <ControlType>select-each-value</ControlType>
                        </Attribute>
                   </ItemData>
              </CurrentItemInfo>
         </DataPanels>
    </IRData>
    <?BASELINE FB2-A.02.01 on:4 off:3?>
    <?BASELINE FB2-A.02.02 on:4 off:4?>
    <?BASELINE FB2-A.03.01 on:3 off:1?>
    <?BASELINE FB2-A.03.02 on:0 off:1?>
    <?BASELINE FB2-A.03.04 on:3 off:2?>
    <?BASELINE FB2-A.03.05 on:1 off:0?>
    <?BASELINE FB2-A.03.07 on:4 off:2?>
    <?BASELINE FB2-A.04.01 on:2 off:5?>
    <?BASELINE FB2-A.04.02 on:5 off:3?>
    <?BASELINE FB2-A.04.03 on:3 off:1?>
    <?BASELINE FB2-A.04.04 on:1 off:1?>
    <?BASELINE FB2-A.05.01 on:12 off:14?>
    <?BASELINE FB2-A.05.02 on:9 off:1?>
    <?BASELINE FB2-A.05.03 on:0 off:6?>
    <?BASELINE FB2-A.06.01 on:7 off:9?>
    <?BASELINE FB2-A.06.02 on:2 off:6?>
    <?BASELINE FB2-A.06.03 on:10 off:5?>
    <?BASELINE FB2-A.06.04 on:1 off:1?>
    <?BASELINE FB2-A.07 on:23 off:20?>

  • 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

  • Error in case when

    hi friends
        i have below query which is throwing error  'missing expression' which is on bold.
        please correct the query.
       SELECT max(lv.lv_lastupdate)  INTO v_old_date FROM loanable_value lv
       WHERE lv.lv_rm_cust_id= p_gfcid AND lv.lv_year= p_year
       AND  (CASE  WHEN     p_Quarter ='Q1'  THEN    lv.lv_month IN ('Jan','Feb','Mar')  END ) ;

    RajnishChauhan wrote:
    hi friends
        i have below query which is throwing error  'missing expression' which is on bold.
        please correct the query.
       SELECT max(lv.lv_lastupdate)  INTO v_old_date FROM loanable_value lv
       WHERE lv.lv_rm_cust_id= p_gfcid AND lv.lv_year= p_year
       AND  (CASE  WHEN     p_Quarter ='Q1'  THEN    lv.lv_month IN ('Jan','Feb','Mar')  END ) ;
    How do you expect us to correct it if we don't know what you want?
    However, I'm guessing you want
    and (
    (p_quarter = 'Q1' and lv.lv_month in ('Jan','Feb','Mar'))
    or (p_quarter = 'Q2' and lv.lv_month in ('Apr','May','Jul'))
    or..
    difficulties you could have avoided if you'd not split things up as lv_year,lv_month etc. and just kept the field as a single DATE.
    Then it would be a simple as
    where to_char(lv.lv_date,'Q')=p_quarter
    where p_quarter is 1,2,3 or 4

Maybe you are looking for

  • Mini DisplayPort to DVI Adapter and macbook pro

    I have a 2010 macbook pro 13", samsung 20" LED display connected via mini display port. The setup has been fine for a few months but occasionally both displays would turn blue as it tries to detect itself(I assume) when this happened I would just nee

  • Query timeout for large table

    Dear friend, My view always shows timeout because my table is now having 18,00,000 data row. Now what should I do with this table? can anyone help me? another question is, in my work purpose I need to create 5-7 report every day. So every time I need

  • How to display full screen in landing page

    Hi, I'd like to create a landing page with own menu bar above, and open the iView in the frame. any idea how to do this ? ex. menu  My Company My Customer iView column 1                   iView column 1 invoices                                  order

  • Apply a new template in Contribute?

    Have an existing site in Contribute that has hundreds of pages.  How do I update the template applied to all of the pages?  I had 2 ideas: 1)  Edit the existing template, keeping all the file and editable region names the same (thinking that the next

  • Got stuck...on linux-p [SOLVED]

    hey all, I tried to install the 'aufs3' package ,but i got stuck [greglee@PSi_baLL ~]$ yaourt aufs3 1 aur/aufs3 3.0_20110829-1 (5)     Another Unionfs Implementation 2 aur/aufs3-util 20110812-1 (3)     Another Unionfs Implementation that supports NFS