Case statement related issue

Dear All,
select gjahr,wtg001, wtg002, XYZ,
  case
  when wtg001 != 0  then concat(gjahr, '001')
  wtg001 as XYZ   <------------------------   Here i want value of wtg001 in XYZ
  else
  case 
  when wtg002 = 0 then concat(gjahr, '002') end  end as gjahr
  from cosp;
-Regards,
Amol

What is the question here?
Also: the AS <column alias> clause can only be used once per column projection definition and it mus be at the end of it.
- Lars

Similar Messages

  • C#/SharePoint -View State related issue while exporting data to excel

    We have web application based on SharePoint. We have a list view to display data based on Search Criteria. We have total of around 16000 data. When we try to export all data to excel it gives an error. The cause of the issue is:
    View State is used to save the state of page i.e. the previous state. When the export to excel link is clicked, the data present in the grid is actually saved in view state so that the overhead of again generating
    the data(as per the selection criteria) can be avoided. Now, this View state has a limitation of storage of these records. When we put in some selection criteria, the no. of records is less hence no problem in actually storing the view state. But when there
    is no selection criteria, 16306 records are too much to be stored in view state. Hence the error occurs.
    We tried to solve this issue by creating a compressor class and overriding two methods:
     LoadPageStateFromPersistenceMedium
    SavePageStateToPersistenceMedium
    This has resolved the issue with Export to Excel. However, there is now some issue in the paging of the list view. The list view has a column with hyperlink which opens related data in a form. While we click on the link in 2<sup>nd</sup>
    page of the list view, it displays data for the link in the 1<sup>st</sup> page at same row.
    Please suggest how to resolve this issue or any workaround for this

    We have web application based on SharePoint. We have a list view to display data based on Search Criteria. We have total of around 16000 data. When we try to export all data to excel it gives an error. The cause of the issue is:
    View State is used to save the state of page i.e. the previous state. When the export to excel link is clicked, the data present in the grid is actually saved in view state so that the overhead of again generating
    the data(as per the selection criteria) can be avoided. Now, this View state has a limitation of storage of these records. When we put in some selection criteria, the no. of records is less hence no problem in actually storing the view state. But when there
    is no selection criteria, 16306 records are too much to be stored in view state. Hence the error occurs.
    We tried to solve this issue by creating a compressor class and overriding two methods:
     LoadPageStateFromPersistenceMedium
    SavePageStateToPersistenceMedium
    This has resolved the issue with Export to Excel. However, there is now some issue in the paging of the list view. The list view has a column with hyperlink which opens related data in a form. While we click on the link in 2<sup>nd</sup>
    page of the list view, it displays data for the link in the 1<sup>st</sup> page at same row.
    Please suggest how to resolve this issue or any workaround for this

  • Issue with TableAdapter Configuration Wizard and CASE statements

    I am having an issue with using any CASE statements in the select clause for the Table Adapter Configuration Wizard (TCW).  I can take any query without a CASE and it will run fine, but inserting any CASE statement in the Select such as:
    SELECT
    (CASE WHEN :ras_sort = 'D' THEN TO_CHAR(a.TRANS_DATE,'YYYYMMDD')
      WHEN :ras_sort = 'C' THEN  c.CLAIMDEP_NAME
      WHEN :ras_sort = 'A' THEN  TO_CHAR(a.ACCOUNT_NUMBER)
      END) sort1
    FROM xxxx
    causes the TCW to error with "error in list of function arguments, 'THEN' not recognized" and several other errors.  I have tried with and without parameters in the CASE and have tried both forms of the CASE statement.  I have tried multiple queries, all that run with no problem outside of TCW and ODP, but this seems to be a real issue
    Is this a known problem and are there any workarounds that will allow use of the TCW?
    Thanks,
    Dave

    Hi Ashish,
    perhaps you launch the Web service wizard from the wrong location (i.e. not selecting the SEI you want to use). Did you strictly follow the steps described in the <a href="http://help.sap.com/saphelp_nwce10/helpdata/en/44/f36fa8fd1d41aae10000000a114a6b/frameset.htm">documentation</a> for creating the web service?

  • 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

  • Issue with case statement

    100*ifnull(x,1)/case when ifnull(yagox,1)=0 then 1 else yagox end)
    based on above condition my result should be like below
    99.8
    101.1
    99.4
    97.7
    Current displaying result like below
    99.8
    1,22,345,000
    99.4
    97.7
    2,34,567,400
    i need to display those two values also in %
    it may be happen denominater(yagox value is 1)
    could please give the proper case statement for resolving the issue
    betham
    Edited by: 961992 on Oct 22, 2012 10:15 PM

    Dear betham,
    welcome to the forum, could you please share the table structure and some sample data and also what your select statement is. This will help people come up with solution faster and also it would avoid going in loops.

  • Case Statement and Group By issues

    Hi this is my initial query which works perfectly:
    select ff.cla_case_no, Cost_before_Decision, Cost_Of_Claim, decline, Decline_Description from
    fraud_nov_14_final ff
    ,(select cla_case_no, (sum(total_cost_adj_old) + sum(decline_estimate)) Cost_before_Decision
    from reporting.ci_final@test
    group by cla_case_no) z
    where ff.cla_case_no = z.cla_case_noI now want to add in a condition based on a column called decline:
    select ff.cla_case_no, Cost_before_Decision, Cost_Of_Claim, ff.decline, Decline_Description from
    fraud_nov_14_final ff
    ,(select cla_case_no, (case when decline = 1 or decline = 2  THEN (sum(total_cost_adj_old) + sum(decline_estimate)) ELSE Total_Cost END) Cost_before_Decision
    from reporting.ci_final@test
    group by cla_case_no) z
    where ff.cla_case_no = z.cla_case_noThe error message I receive is :
    ORA-00979: not a GROUP BY expression
    00979. 00000 - "not a GROUP BY expression"
    Thanks in advance for your help!!
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    You would need DECLINE in the group by clause of your inner query.
    Additionally you would need to change TOTAL_COST to SUM(TOTAL_COST) in where case statement.
    But then you would retrieve one row for each value of DECLINE in this query.
    You also could use this:
    (I don't know if it will meet your requirements)
    SELECT ff.cla_case_no,
                     cost_before_decision,
                     cost_of_claim,
                     ff.decline,
                     decline_description
      FROM fraud_nov_14_final ff,
                     (SELECT   cla_case_no,
                               SUM (decode(decline,1,total_cost_adj_old+decline_estimate,
                                                   2,total_cost_adj_old+decline_estimate,
                                                   total_cost))  cost_before_decision
                                    FROM reporting.ci_final@test
                      GROUP BY cla_case_no) z
    WHERE ff.cla_case_no = z.cla_case_no;(untested code, because I don't have your tables)
    Edited by: hm on 23.11.2011 06:52

  • Case Statement Issue

    Hi All,
    I need help figuring out a simple case statement. I need to add an OR condition to a couple of the statements and also have a condition that will return everyting. The first query works but lacks the OR condtion/statement. Any help is appreciated.
    Select item_no
    from item
    where item_id =
    case
    when &p_item = '123' then '123'
    when &p_item = '133' then '133'
    when &p_item = '444' then '444'
    end
    How can i do the following?
    Select item_no
    from item
    where item_id =
    case
    when &p_item = '123' then '123' or null
    when &p_item = '133' then '133' or null
    when &p_item = '444' then '444'
    when &p_item = '999' then return all records
    end

    Hi,
    Like Raghu, I wouldn't use a CASE espression. You can put conditions in a a WHERE clause jsut fione without CASE.
    For example:
    SELECT  item_no
    FROM     item
    WHERE     (     '&p_item'     IN ('123', '133')
         AND     '&p_item'     = NVL ( item_id
                              , '&p_item'
    OR     (     '&p_item'     IN ('444')
         AND     '&p_item'     = item_id
    OR     '&p_item'     IN ('999')
    OR     '&p_item'     IS NULL
    ;If you really, really want to use a CASE exprtession, then you can do something like this:
    SELECT  item_no
    FROM     item
    WHERE     CASE
             WHEN  '&p_item'     IN ('123', '133')
             AND       '&p_item,'     = NVL ( item_id
                              , '&p_item'
                 THEN  '123, 133'
             WHEN  '&p_item'     IN ('444')
             AND       '&p_item'     = item_id
                 THEN  '444'
             WHEN  '&p_item'     IN ('999')
                 THEN  '999'
             WHEN  '&p_item'     IS NULL
                   THEN  'NO P_ITEM'
               ELSE  NULL
            END     IS NOT NULL
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data, for each of a few values of &p_item..
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    Edited by: Frank Kulash on Sep 15, 2011 12:29 PM

  • Excel and CASE statement.

    Hello Experts,
    I am using a CASE statement on CHAR column as follows:
    CASE WHEN Sales.Ret='Y' THEN 'Returning' ELSE 'New' END
    It gives an error: Odbc driver returned an error (SQLExecDirectW).
    Whereas when I use another CASE statement with Numrical column it is working perfectly.
    CASE WHEN Sales.Amount<40 THEN 40 ELSE 100 END
    Am i missing some Excel data source setting related to CHAR data type?
    My source is MS Excel 2003 and OBIEE is 10.1.3.4.1
    Appreciate any comment, help.
    ~ Ash
    PS: The error details are as follows:*
    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: 37000 code: -3100 message: [Microsoft][ODBC Excel Driver] Syntax error (missing operator) in query expression 'case when T46.[Ret] = 'Y' then 'Returning' else 'New' end'.. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SELECT Sales.Tran_date saw_0, CASE WHEN Sales.Ret='Y' THEN 'Returning' ELSE 'New' END saw_1, Network."Network Name" saw_2, Sales.Amount saw_3 FROM P4UD ORDER BY saw_0, saw_1, saw_2

    Hello Saichand,
    I would like to reconfirm that the CASE statement with Numeric column is working with EXCEL as source.
    The strange thing is that the CASE statement with CHAR column was also working! and from one fine day it it started throwing an error (i thought some source setting might got changed inadvertently ).
    Thank you for your response but I would like to see comments/suggestions from other experts..
    ~ Ash
    Edited by: OBIEE_Ash on Dec 20, 2010 10:27 PM

  • RE: Case 59063: performance issues w/ C TLIB and Forte3M

    Hi James,
    Could you give me a call, I am at my desk.
    I had meetings all day and couldn't respond to your calls earlier.
    -----Original Message-----
    From: James Min [mailto:jminbrio.forte.com]
    Sent: Thursday, March 30, 2000 2:50 PM
    To: Sharma, Sandeep; Pyatetskiy, Alexander
    Cc: sophiaforte.com; kenlforte.com; Tenerelli, Mike
    Subject: Re: Case 59063: performance issues w/ C TLIB and Forte 3M
    Hello,
    I just want to reiterate that we are very committed to working on
    this issue, and that our goal is to find out the root of the problem. But
    first I'd like to narrow down the avenues by process of elimination.
    Open Cursor is something that is commonly used in today's RDBMS. I
    know that you must test your query in ISQL using some kind of execute
    immediate, but Sybase should be able to handle an open cursor. I was
    wondering if your Sybase expert commented on the fact that the server is
    not responding to commonly used command like 'open cursor'. According to
    our developer, we are merely following the API from Sybase, and open cursor
    is not something that particularly slows down a query for several minutes
    (except maybe the very first time). The logs show that Forte is waiting for
    a status from the DB server. Actually, using prepared statements and open
    cursor ends up being more efficient in the long run.
    Some questions:
    1) Have you tried to do a prepared statement with open cursor in your ISQL
    session? If so, did it have the same slowness?
    2) How big is the table you are querying? How many rows are there? How many
    are returned?
    3) When there is a hang in Forte, is there disk-spinning or CPU usage in
    the database server side? On the Forte side? Absolutely no activity at all?
    We actually have a Sybase set-up here, and if you wish, we could test out
    your database and Forte PEX here. Since your queries seems to be running
    off of only one table, this might be the best option, as we could look at
    everything here, in house. To do this:
    a) BCP out the data into a flat file. (character format to make it portable)
    b) we need a script to create the table and indexes.
    c) the Forte PEX file of the app to test this out.
    d) the SQL staement that you issue in ISQL for comparison.
    If the situation warrants, we can give a concrete example of
    possible errors/bugs to a developer. Dial-in is still an option, but to be
    able to look at the TOOL code, database setup, etc. without the limitations
    of dial-up may be faster and more efficient. Please let me know if you can
    provide this, as well as the answers to the above questions, or if you have
    any questions.
    Regards,
    At 08:05 AM 3/30/00 -0500, Sharma, Sandeep wrote:
    James, Ken:
    FYI, see attached response from our Sybase expert, Dani Sasmita. She has
    already tried what you suggested and results are enclosed.
    ++
    Sandeep
    -----Original Message-----
    From: SASMITA, DANIAR
    Sent: Wednesday, March 29, 2000 6:43 PM
    To: Pyatetskiy, Alexander
    Cc: Sharma, Sandeep; Tenerelli, Mike
    Subject: Re: FW: Case 59063: Select using LIKE has performance
    issues
    w/ CTLIB and Forte 3M
    We did that trick already.
    When it is hanging, I can see what is doing.
    It is doing OPEN CURSOR. But not clear the exact statement of the cursor
    it is trying to open.
    When we run the query directly to Sybase, not using Forte, it is clearly
    not opening any cursor.
    And running it directly to Sybase many times, the response is always
    consistently fast.
    It is just when the query runs from Forte to Sybase, it opens a cursor.
    But again, in the Forte code, Alex is not using any cursor.
    In trying to capture the query,we even tried to audit any statementcoming
    to Sybase. Same thing, just open cursor. No cursor declaration anywhere.==============================================
    James Min
    Technical Support Engineer - Forte Tools
    Sun Microsystems, Inc.
    1800 Harrison St., 17th Fl.
    Oakland, CA 94612
    james.minsun.com
    510.869.2056
    ==============================================
    Support Hotline: 510-451-5400
    CUSTOMERS open a NEW CASE with Technical Support:
    http://www.forte.com/support/case_entry.html
    CUSTOMERS view your cases and enter follow-up transactions:
    http://www.forte.com/support/view_calls.html

    Earthlink wrote:
    Contrary to my understanding, the <font face="courier">with_pipeline</font> procedure runs 6 time slower than the legacy <font face="courier">no_pipeline</font> procedure. Am I missing something? Well, we're missing a lot here.
    Like:
    - a database version
    - how did you test
    - what data do you have, how is it distributed, indexed
    and so on.
    If you want to find out what's going on then use a TRACE with wait events.
    All nessecary steps are explained in these threads:
    HOW TO: Post a SQL statement tuning request - template posting
    http://oracle-randolf.blogspot.com/2009/02/basic-sql-statement-performance.html
    Another nice one is RUNSTATS:
    http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551378329289980701

  • CASE Statement in Where Condition with Multi Valued parameter in SSRS

    Hi All,
    I am little confused while using CASE statement in Where condition in SSRS. Below is my scenario:
    SELECT
    Logic here
    WHERE
    Date IN (@Date)AND
    (CASE
    WHEN NAME LIKE 'ABC%' THEN 'GROUP1'
    WHEN ID IN ('123456', '823423','74233784') THEN 'GROUP2'
    WHEN ABC_ID IS NULL THEN 'GROUP3'
    ELSE 'GROUP4'
    END ) IN (@GROUP)
    So above query uses WHERE condition with CASE statement from @GROUP parameter. I want to pass this parameter as multi- valued parameter and hence I have used CASE statement IN (@GROUP).
    For @Date one dataset will pass the available and default values and
    for @GROUP parameters, another dataset will pass the available and default values.
    But this is not working as expected. Please suggest me where I am making mistake in the query.
    Maruthu | http://sharepoint-works.blogspot.com

    Hi Maruthu,
    According to your description, I create a sample report in my local environment. It works as I expected. In your scenario, if the selected values from the Date parameter contains some of the Date field values, the selected values from the GROUP parameter
    contains some of GROUPS (‘GROUP1’,’GROUP2’,’GROUP3’,’GROUP4’) and the corresponding when statement is executed , then the dataset returns the corresponding values.
    In order to trouble shoot this issue, could you tell us what results are you get and what’s your desired results? If possible, you can post the sample data with sample dataset, then we can make further analysis and help you out.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • [Oracle 8i] Handling null in case statement

    The following bit of my query is causing the error 'inconsistent datatypes':
    CASE
         WHEN b.days_diff < 0
         THEN plan_start
         ELSE plan_start + b.days_diff
    ENDThe problem is that b.days_diff can be null.
    I've tried to work around this, by using the NVL statement and by nesting 2 case statements to try to deal with the null, but can't seem to work around it.
    Does anyone have anything else I can try?

    Apologies...internet server went down yesterday...
    I've had this issue before with my database. When I look at user_tab_columns, it says plan_start is a date. However, I have had to use TO_DATE in the past with it to get some things to work. It's very odd, and I have no idea why it's like that.
    Anyway, below, I have provided some sample data, and the full query I'm trying to run:
    CREATE TABLE     ord (
    ord_nbr          char(10)
    ord_stat     char(2)
    INSERT INTO     ord
    VALUES          ('0000012345', 'OP');
    INSERT INTO     ord
    VALUES          ('0000012346', 'OP');
    INSERT INTO     ord
    VALUES          ('0000012347', 'CL');
    INSERT INTO     ord
    VALUES          ('0000012348', 'OP');
    CREATE TABLE     op (
    ord_nbr          char(10)
    operation     char(4)
    op_status     char(2)
    plan_start     date
    pln_due          date
    dt_complete     date
    INSERT INTO     op
    VALUES          ('0000012345', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-04 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0002', 'CL', {ts '2009-01-02 00:00:00'}, {ts '2009-01-03 00:00:00'}, {ts '2009-01-06 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0003', 'CL', {ts '2009-01-03 00:00:00'}, {ts '2009-01-04 00:00:00'}, {ts '2009-01-09 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0004', 'WK', {ts '2009-01-04 00:00:00'}, {ts '2009-01-05 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012345', '0005', 'OP', {ts '2009-01-05 00:00:00'}, {ts '2009-01-06 00:00:00'}, {ts '2009-01-02 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-01 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0002', 'OP', {ts '2009-01-02 00:00:00'}, {ts '2009-01-04 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012346', '0003', 'OP', {ts '2009-01-04 00:00:00'}, {ts '2009-01-06 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012347', '0001', 'CL', {ts '2009-01-01 00:00:00'}, {ts '2009-01-02 00:00:00'}, {ts '2009-01-03 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012347', '0002', 'CL', {ts '2009-01-02 00:00:00'}, {ts '2009-01-05 00:00:00'}, {ts '2009-01-06 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012348', '0001', 'OP', {ts '2009-01-15 00:00:00'}, {ts '2009-01-17 00:00:00'}, {ts '1900-12-31 00:00:00'});
    INSERT INTO     op
    VALUES          ('0000012348', '0002', 'OP', {ts '2009-01-17 00:00:00'}, {ts '2009-01-20 00:00:00'}, {ts '1900-12-31 00:00:00'});Full query:
    SELECT     ord.ord_nbr
    ,     ord.ord_stat
    ,     op.operation
    ,     op.op_status
    ,     op.plan_start
    ,     //where I want to return plan_start + days_diff if days_diff is not null or negative
         //otherwise, I want to return just plan_start
         AS adjusted_start
    ,     op.dt_complete
    ,     b.max_cl_op
    ,     b.pln_due
    ,     b.dt_complete
    ,     b.days_diff
    FROM     ord
    ,     op
         SELECT     a.ord_nbr
         ,     a.max_cl_op
         ,     op.pln_due
         ,     op.dt_complete
         ,     (op.dt_complete-op.pln_due)     AS days_diff
         FROM     (
              SELECT          op.ord_nbr
              ,          MAX(TO_NUMBER(op.operation))     AS max_cl_op
              FROM          ord
              ,          op
              WHERE          ord.ord_nbr     = op.ord_nbr
              AND          ord.ord_stat     != 'CL'
              AND          op.op_status     ='CL'
              GROUP BY     op.ord_nbr
              ) a
         WHERE     op.ord_nbr     = a.ord_nbr
         AND     op.operation     = a.max_cl_op
         ) b
    WHERE     ord.ord_nbr     = op.ord_nbr
    AND     op.ord_nbr     = b.ord_nbr (+)
    AND     ord.ord_stat     != 'CL'
    AND     op.op_status     != 'CL'
    AND     op.plan_start     <= ADD_MONTHS(sysdate, 12)The results I want to get:
    ord.ord_nbr     ord.ord_stat     op.operation     op.op_status     op.plan_start     adjusted_start     op.dt_complete     b.max_cl_op     b.pln_due     b.dt_complete     b.days_diff
    '0000012345'     'OP'          '0004'          'WK'          1/4/2009     1/9/2009     12/31/1900     '0003'          1/4/2009     1/9/2009     5     
    '0000012345'     'OP'          '0005'          'OP'          1/5/2009     1/10/2009     12/31/1900     '0003'          1/4/2009     1/9/2009     5
    '0000012346'     'OP'          '0002'          'OP'          1/2/2009     1/2/2009     12/31/1900     '0001'          1/2/2009     1/1/2009     -1
    '0000012346'     'OP'          '0003'          'OP'          1/4/2009     1/4/2009     12/31/1900     '0001'          1/2/2009     1/1/2009     -1
    '0000012348'     'OP'          '0001'          'OP'          1/15/2009     1/15/2009     12/31/1900                                   
    '0000012348'     'OP'          '0002'          'OP'          1/17/2009     1/17/2009     12/31/1900     

  • Case Statement in sub query

    Hi, I have two issues, here is my initial code:
    select
    cc.name_id_no
    ,cc.discover_date
    ,cc.cla_case_no
    ,max(rl.year_of_incident)Non_Loss_Past_5
    ,rl.timestamp
    from cla_case cc, rbn_loss rl
    where cc.name_id_no = rl.customer_no
    and rl.year_of_incident < trunc(cc.discover_date)
    and rl.type_of_loss < 1000
    and rl.timestamp < trunc(cc.discover_date)
    and (cc.question_class = 20
    or cc.question_class = 25)
    and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
    --and (trunc(cc.discover_date) <> (rl.year_of_incident))
    group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
    Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.
    To get around this I did the following which is not very efficient and I'm hoping it can be improved:
    select distinct z.cla_case_no from (
    select
    cc.name_id_no
    ,cc.discover_date
    ,cc.cla_case_no
    ,max(rl.year_of_incident)Non_MW_Loss_Past_5
    ,rl.timestamp
    from cla_case cc, rbn_loss rl
    where cc.name_id_no = rl.customer_no
    and rl.year_of_incident < trunc(cc.discover_date)
    and rl.type_of_loss < 1000
    and rl.timestamp < trunc(cc.discover_date)
    and (cc.question_class = 20
    or cc.question_class = 25)
    and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
    --and (trunc(cc.discover_date) <> (rl.year_of_incident))
    group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
    ) z
    Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
    SELECT
    ie ,(select distinct z.cla_case_no from (
    select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
    from cla_case cc, rbn_loss rl
    where cc.name_id_no = rl.customer_no
    and rl.year_of_incident < trunc(cc.discover_date)
    and rl.type_of_loss < 1000
    and rl.timestamp < trunc(cc.discover_date)
    and (cc.question_class = 20
    or cc.question_class = 25)
    and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
    --and (trunc(cc.discover_date) <> (rl.year_of_incident))
    group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
    ) z
    where z.cla_case_no = ccx.cla_case_no
    ) Non_MW_Loss_Past_5
    FROM etc
    Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
    What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
    Thanks!!!
    Banner:
    Oracle Database 11g Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    "CORE 11.2.0.2.0 Production"
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Hi,
    It looks like you have another copy of this question:
    Case Statement and sub query
    That's probably not your fault, but you should mark the other copy as "Answered" right away, and then you'll only have to look for replies in one place.
    885178 wrote:
    ... Now a cla_case_no can map to several year_of_incident. I only want the cla_case_no that maps to the max year_of_incident ie There should only be a single cla_case_no corresponding to the max year_of_incident.If you know there will only be one, then you can use LAST, and you don't need GrOUP BY
    To get around this I did the following which is not very efficient and I'm hoping it can be improved:
    select distinct z.cla_case_no from (
    select
    cc.name_id_no
    ,cc.discover_date
    ,cc.cla_case_no
    ,max(rl.year_of_incident)Non_MW_Loss_Past_5
    ,rl.timestamp
    from cla_case cc, rbn_loss rl
    where cc.name_id_no = rl.customer_no
    and rl.year_of_incident < trunc(cc.discover_date)
    and rl.type_of_loss < 1000
    and rl.timestamp < trunc(cc.discover_date)
    and (cc.question_class = 20
    or cc.question_class = 25)
    and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
    --and (trunc(cc.discover_date) <> (rl.year_of_incident))
    group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
    ) zHere's one way:
    SELECT       MIN (cla_case_no) KEEP (DENSE_RANK LAST ORDER BY r1.year_of_incident)
                         AS latest_cla_case_no
    FROM       cla_case     cc
    ,             rbn_loss      rl
    WHERE     cc.name_id_no          = rl.customer_no
    AND       rl.year_of_incident     > TRUNC (cc.discover_date) - 1095
    AND       rl.year_of_incident      < TRUNC (cc.discover_date)
    AND       rl.type_of_loss     < 1000
    AND       rl.timestamp          < TRUNC (cc.discover_date)
    AND       cc.question_class     IN (20, 25)
    ;If you'd post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data, then I could test this.
    Now comes the second issue: The above is actually a subquery that will link to a bigger table via cla_case_no ccx
    SELECT
    ie ,(select distinct z.cla_case_no from (
    select cc.name_id_no, cc.discover_date ,cc.cla_case_no, max(rl.year_of_incident)Non_MW_Loss_Past_5, rl.timestamp
    from cla_case cc, rbn_loss rl
    where cc.name_id_no = rl.customer_no
    and rl.year_of_incident < trunc(cc.discover_date)
    and rl.type_of_loss < 1000
    and rl.timestamp < trunc(cc.discover_date)
    and (cc.question_class = 20
    or cc.question_class = 25)
    and (trunc(cc.discover_date)- (rl.year_of_incident)) < 1095
    --and (trunc(cc.discover_date) <> (rl.year_of_incident))
    group by cc.cla_case_no,name_id_no, cc.discover_date,rl.timestamp
    ) z
    where z.cla_case_no = ccx.cla_case_no
    ) Non_MW_Loss_Past_5
    FROM etc
    Now only certain cc.cla_case_no from the subquery will corresp to the ccx_cla_case_no from the main table and the other entries will be null.
    What I require is that if the subquery returns a result that IS NOT NULL to return 'Y' ELSE 'N' instead of the varies cla_case_no's and (null) entries in the Non_MW_Loss_Past_5 column
    NVL2 (x, 'Y', 'N')returns 'Y' if x is NULL, and it returns 'N' if x is not NULL. X can be a scalar sub-query:
    NVL2 ((SELECT ...), 'Y', 'N')You could also use an EXISTS sub-query:
    CASE
        WHEN  EXISTS (SELECT ...)
        THEN  'Y'
        ELSE  'N'
    END

  • Case Statement in Oracle Query.

    Hello Oracle Gurus,
    I need suggestion on whether I should use Case statement in Oracle queries.
    I have a sql statement which inserts the data by selecting data from other table. While selecting the data I have put a logic in the select statement for one column which is something like this and there are some more similar statements in the same query.
    CASE
                   WHEN (b.ACCOUNT = 'FIN' or b.ACCOUNT ='FIN ACC' or b.ACCOUNT like '%Global Eq%' or b.ACCOUNT like '%Flexible Bond%')
                   THEN
                        'MTM'
                             WHEN (substr(a.CTC,-3)='MTM')
                   THEN
                        'MTM'
                             WHEN (substr(a.CTC,-3)='AFS' or substr(a.CTC,-3)='HTM' OR substr(a.CTC,-3)='ACC' OR substr(a.CTC,-3)='HFI' )
                   THEN
                        'ACC'
                   ELSE
                                  'OTH'
              END,
    I wanted to get an suggestion about how much performance issue can I have due to this in my insert statement.
    Let me know if you need any other information.All comments are really appreciated.

    Hi,
    It's depends on the joins how you have performed with source table, stats and existing of indexes. If the volume of data is high - in case of any performance issue - why can't you perform the required things of logical conditions of data and popualte in one cluster so - that you can fetch out the chunks of required information with better way and in support with indexes.
    Let us know the ful query your working on
    Oracle version
    Explain plans - get it from dbms_xplan.
    - Pavan Kumar N
    - ORACLE - 9i/10g - OCP
    RHCE - Enterprize Linux 5.4

  • 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

  • CASE statement in Oracle 8i PL/SQL

    I'm in the process of doing an upgrade from 8i to 10g and have the necessary instructions in performing it. however, after running the pre upgrade tasks (run utlu102i.sql) to show the preupgrade information, i found out that there are some INVALID objects.
    Miscellaneous Warnings
    WARNING: --> Database contains INVALID objects prior to upgrade.
    .... USER INGITRN has 1 INVALID objects.
    .... USER INGIUAT has 3 INVALID objects.
    .... USER OEMMON has 7 INVALID objects.
    .... USER RE_ITF_USER has 11 INVALID objects.
    .... USER SYS has 1 INVALID objects.
    Would it be ok to proceed with the upgrade and ignore the warnings?
    Also, as i checked the invalid object for SYS, it shows:
    OWNER OBJECT_NAME OBJECT_TYPE STATUS
    SYS UTL_RECOMP PACKAGE VALID
    SYS UTL_RECOMP PACKAGE BODY INVALID
    Further more, i tried to do a fix by invoking utlirp.sql and the same objects are showing up. Same thing shows when invoking utlrp.sql or even doing a manual compile for the affected objects. I later found out that CASE statements are not accepted in PL/SQL for Oracle 8i.
    Can you help me fixed the issue on the invalid object?
    Thanks

    Hi,
    Try first to (re)compile ll invalid objects. then
    you can run:
    select owner,type,count(*) from all_errors
    group by owner,typeif you still have uncompiled objects, then report the different errors:
    select * from all_errors...

Maybe you are looking for