Using Case When

I have a situation where i need to write a case when sql expression to fetch certain rows from a table.
How to use CASE WHEN THEN ELSE END in a report query ?
Explanation with a simple example will be of great help.
thanks

The javadoc for oracle.toplink.expressions.Expression
contains some information.
The following is an example of how to build the case statement.
This will use case to replace the keys in the caseTable with the values. The default value (the ELSE) is provided as the second argument.
     Hashtable caseTable = new Hashtable(3);
     caseTable.put("Bob", "Bobby");
     caseTable.put("Susan", "Susie");
     caseTable.put("Eldrick", "Tiger");
     Expression expression = builder.get("firstName").caseStatement(caseTable, "No-Nickname").equal("Bobby");

Similar Messages

  • Using case when statement or decode stament in where clause

    hi gems..
    i have a problem in the following query..
    i am trying to use case when statement in the where clause of a select query.
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
    cr.salary as salary
    from customer_details cr
    where (case when '>' = '>' then 'cr.salary > 5000'
    when '>' = '<' then 'cr.salary < 5000'
    when '>' = '=' then 'cr.salary = 5000'
    else null
    end);
    the expression in the when clause of the case-when statement will come from UI and depending on the choice i need to make the where clause.
    thats why for running the query, i have put '>' in that place.
    so the original query will look like this(for your reference):
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
    cr.salary as salary
    from customer_details cr
    where (case when variable = '>' then 'cr.salary > 5000'
    when variable = '<' then 'cr.salary < 5000'
    when variable = '=' then 'cr.salary = 5000'
    else null
    end);
    so, in actual case,if the user selects '>' then the filter will be "where cr.salary > 5000"
    if the user selects '<' then the filter will be "where cr.salary < 5000"
    if the user selects '=' then the filter will be "where cr.salary = 5000"
    but i am getting the error "ORA 00920:invalid relational operator"
    please help..thanks in advance..

    Hi,
    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
           cr.salary                                      as salary
    from customer_details cr
    where (    v_variable = 'bigger'
           and cr.salary > 5000
       or (    v_variable = 'less'
          and cr.salary < 5000
       or (    v_variable = 'eq'
            and cr.salary = 5000
           )Edited by: user6806750 on 22.12.2011 14:56
    For some reason I can't write in sql '<', '>', '='

  • 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

  • How to use case when in Select qry?

    Hi Friends,
    I want to use Case when in Select qry, my situation is like this
    SELECT bmatnr blgort bj_3asiz bmat_kdauf b~mat_kdpos
           SUM( ( case when bshkzg = 'S' then bmenge else 0 END ) -
            ( case when bshkzg = 'H' then bmenge else 0 END ) ) AS qty
           INTO corresponding fields of table it_projsal
        FROM mseg AS b
            INNER JOIN mkpf AS a ON bmblnr = amblnr
                                AND bmandt = amandt
        WHERE abudat  < '20061201' AND blgort IN ('1050')
          and b~mandt = '350'
        GROUP BY bmatnr bj_3asiz bmat_kdauf bmat_kdpos b~lgor
    If we give like this it gives an error.
    Please help me, how to use or handle in select qry itself.
    Regards
    Shankar

    this is not a way to select data from the DB tables.
    first get all the data from the DB tables then u have to do SUM Ups .
    Regards
    prabhu

  • Update multiple rows using CASE WHEN

    I have the table ACCOUNT of structure as follow: 
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something missing
    UPDATE ACCOUNT
    SET ACCOUNT_STATUS = CASE  
    WHEN ACCOUNT_STATUS = '004460721' THEN 5 
    WHEN ACCOUNT_STATUS = '042056291' THEN 3 
    WHEN ACCOUNT_STATUS = '601272065' THEN 2 
    WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 
    My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?

    Hi,
    Hawk333 wrote:
    I have the table ACCOUNT of structure as follow:
    ACCOUNT_ID
    ACCOUNT_STATUS
    004460721
    2
    042056291
    5
    601272065
    3
    I need to update the three rows at once using one SELECT statement such that, the second column will be 5, 3, 2 respectively.
    I used the following query but seems there is something missing
    UPDATE ACCOUNT
    SET ACCOUNT_STATUS = CASE  
    WHEN ACCOUNT_STATUS = '004460721' THEN 5 
    WHEN ACCOUNT_STATUS = '042056291' THEN 3 
    WHEN ACCOUNT_STATUS = '601272065' THEN 2 
    WHERE ACCOUNT_ID IN ('004460721','042056291','601272065') 
    My question, is this way correct? if no, can I use CASE WHEN statement and how or I only have choice of using SUB-SELECT to acheive that in one statement?
    What happens when you try it?
    Did you mean "WHEN ACCOUNT_ID = ..."?
    A CASE expressions always needs an END keyword.
    Depending on your requirements (that is, why are those rows being changed, and how do you determine the new values) a CASE expression in an UPDATE statement, similar to what you posted, could be a good way to do it.  MERGE (instead of UPDATE) would also be an option, especially if you want to avoid updating rows that already happen to have the correct values.

  • Insert using case when

    hello ,
    i wanna use "case when" statement in the insert , i implement it like this :
    currentyear:=1;
    insert into test1 (ATTRIB1,ATTRIB2) values ((case when currentyear=1 then 'ok' else 'notOK' end),'val2' );
    but it didn't work, i got this error :
    ORA-14551: cannot perform a DML operation inside a query
    Regards
    Elyes
    Edited by: user10393090 on 5 janv. 2009 03:32

    Better approach is ->
    insert into test1 (ATTRIB1,ATTRIB2)
    select case
             when &currentyear=1 then
              'ok'
           else
             'notOK'
           end AS attrib1,
           'val2' AS attrib2
    from dual;N.B.: Not Tested...
    Regards.
    Satyaki De.

  • How to use case when function to calculate time ?

    Dear All,
    May i know how to use case when function to calculate the time ?
    for the example , if the First_EP_scan_time is 12.30,  then must minus 30 min.  
    CASE WHEN FIRSTSCAN.EP_SHIFT <> 'R1' AND FIRSTSCAN.EP_SHIFT <> 'R2'
    THEN ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF((CASE WHEN SHIFTCAL.EP_SHIFT = 'N1'
    THEN CONVERT(VARCHAR(8),DATEADD(DAY,+1,LEFT(FIRSTSCAN.EP_SCAN_DATE ,8)),112) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','')
    ELSE LEFT(FIRSTSCAN.EP_SCAN_DATE ,8) + ' ' + REPLACE(CONVERT(VARCHAR(8),DATEADD(HOUR,+0,SHIFTDESC.EP_SHIFT_TIMETO + ':00'),108),':','') END),12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0 - 0.25) AS FLOAT),2)
    ELSE ROUND(CAST((DATEDIFF(MINUTE,CAST(STUFF(STUFF(FIRSTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME),CAST(STUFF(STUFF(LASTSCAN.EP_SCAN_DATE,12,0,':'),15,0,':') AS DATETIME)) / 60.0) AS FLOAT),2) END AS OTWORK_HOUR

    Do not use computations in a declarative language.  This is SQL and not COBOL.
    Use a table of time slots set to one more decimal second of precision than your data. You can now use temporal math to add it to a DATE to TIME(1) get a full DATETIME2(0). Here is the basic skeleton. 
    CREATE TABLE Timeslots
    (slot_start_time TIME(1) NOT NULL PRIMARY KEY,
     slot_end_time TIME(1) NOT NULL,
     CHECK (start_time < end_time));
    INSERT INTO Timeslots  --15 min intervals 
    VALUES ('00:00:00.0', '00:14:59.9'),
    ('00:15:00.0', '00:29:59.9'),
    ('00:30:00.0', '00:44:59.9'),
    ('00:45:00.0', '01:00:59.9'), 
    ('23:45:00.0', '23:59:59.9'); 
    Here is the basic query for rounding down to a time slot. 
    SELECT CAST (@in_timestamp AS DATE), T.start_time
      FROM Timeslots AS T
     WHERE CAST (@in_timestamp AS TIME)
           BETWEEN T.slot_start_time 
               AND T.slot_end_time;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Using case when statement in the select query to create physical table

    Hello,
    I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
    I have a physical table based on a select table with one column.
    SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
    I also have a customer table.
    In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
    In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
    EXECUTION
    When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
    everything works as expected. YE!!
    Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
    SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
    FROM DUAL
    Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
    surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
    SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
    If anyone has any explanation to this error and how we can achieve the same, please help.
    Thanks.

    Hello,
    Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
    I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
    Here is what I am trying to do. the select query of the physical table is as follows.
    SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
    The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
    Thanks.

  • Using CASE WHEN to change background color

    I've done this many times without any problems, but this time its a little different situation and I can't get it to work.
    I can use this CASE WHEN statement without any problems.
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where
    EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    '<span style="color:brown;background-color:yellow">'||NAME||'</font>'
    ELSE "NAME"
    END
    "NAME",
    But I Cant Get This One to Work
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where
    EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    '<span style="color:brown;background-color:yellow">'||NAME_DISPLAY||'</font>'
    ELSE "NAME"
    END
    "NAME" NAME_DISPLAY,
    I'm sure that the problem lies with <"NAME" NAME_DISPLAY> but I can't find my way to a solution.
    Does anyone have any ideas for me?

    I've done this many times without any problems, but this time its a little different situation and I can't get it to work.
    I can use this CASE WHEN statement without any problems.
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    (ignore this) span style="color:brown;background-color:yellow">'||NAME||' (ignore this)
    ELSE "NAME"
    END
    "NAME",
    But I Cant Get This One to Work
    CASE WHEN
    NAME in
    (select EMP_REQUEST_NAME from OAX_PTA_LOGGER where EMP_REQUEST_NAME = NAME and
    EMP_ASSIST_NAME is null and
    JOB_NO = :P24_JOB_NO)
    THEN
    (ignore this) span style="color:brown;background-color:yellow">'||NAME||' (ignore this)
    ELSE "NAME"
    END
    "NAME" NAME_DISPLAY,
    I'm sure that the problem lies with <"NAME" NAME_DISPLAY> but I can't find my way to a solution. Does anyone have any ideas for me?

  • Using CASE WHEN for Essbase column in OBIEE 11g

    Hi all,
    I have a business model in OBIEE 11g, taking the source from Essbase 11. The measures of the Essbase cube in the physical layer is flattened, and the aggregations for the measures are set to SUM.
    The Product dimension has 5 generations. In Product logical table, I created a logical column called "Product Grouping" using a simple CASE WHEN formula:
    CASE
    WHEN "TEST"."Product"."Gen5,Product" IN ('100-10', '100-20', '200-10', '300-10') THEN 'Group 1'
    WHEN "TEST"."Product"."Gen5,Product" IN ('100-30', '200-20') THEN 'Group 2'
    ELSE 'Group 3'
    END
    Problems:
    1. If I don't place this "Product Grouping" in the logical level/hierarchy, I got error in the report when I simply show Product Grouping and a measure.
    2. If I place this "Product Grouping" in the logical level/hierarchy (on the 5th level), no more error in the report when I simply show "Product Grouping" and a measure. The measure value also shows the correct SUM (group by). However, when I add "Gen1,Product" the "Product Grouping" and the measure value suddenly becomes not grouped by.
    Has anyone ever tried and encountered something like this? Any thoughts?
    Thank you very much!

    Hi Deepak, thansk for the suggestion.
    However, I can't use calculated item for this report because:
    1. incorrect result will be shown when my measures involve a formula to derive a percentage value.
    2. calculated item is not available if we do "combine requests" (or union) in 11g.
    Any thoughts anyone on how to solve this? Is this just me, or it's a bug?
    Thank you very much.

  • Using case when to an aggregate function

    Hi,
    I have a sql statement like below,
    Select CASE WHEN (Sum(Amount) Over (Partition By Name),1,1) = '-' THEN 0 ELSE Sum(Amount) Over (Partition By Name) END AS Amount_Person
    From tbPerson
    But when I run the sql statement above I got error ORA-00920: invalid relational operator. What I'm trying to do is when the total amount for each person is negative then it will return 0 else it will return the positive value. I dont want to use the GROUP BY function. Is there any other way than using the Sum Over function? Thanks

    Like this?
    SELECT CASE WHEN Sum(Amount) Over (Partition By Name) < 0 THEN 0
                ELSE Sum(Amount) Over (Partition By Name)
           END AS Amount_Person
    FROM tbPerson
    ;or using GREATEST function :
    SELECT GREATEST(
             Sum(Amount) Over (Partition By Name)
           , 0
           ) as Amount_Person
    FROM tbPerson
    ;Edited by: odie_63 on 24 févr. 2011 09:12

  • Using :case when  in where clause

    Hello,
    I need some help with using of case statement in a where clause
    Table that contains info about employees taking some coursework:
    Class (values could be SAP, ORACLE, JAVA)
    Code (if Class is SAP then CODE is not null; if class is any other CODE is NULL)
    Start Date (date they began class not null)
    End Date (date then ended the class - could be null)
    Employee Level(numbers from one through five)
    I need a single LOV in forms that should show Employee_Level for input class,code,date.
    How to do this?
    I started off with this but get 'missing statement error'
    select distinct employee_level from e_course
       where (
       case when &class='SAP' then code ='1' and start_date > to_date('20000101','YYYYMMDD') and
                                               end_date < to_date('20000101','YYYYMMDD')
               else
                   null
       end) order by employee_level;Thanks

    Hi,
    user469956 wrote:
    But all these examples have only one condition for each case.Depending on how you count, all WHERE clauses have only one condition.
    I see an example in that thread that has 6 atomic conditions, linked by AND and OR.
    I need to check date & code. This is what is causing the error.Why do you want to use a CASE statement?
    Why can't you put all your conditions directly iinto a WHERE clause, soemthing like this:
    WHERE   (   &class='SAP'
            AND code ='1'
    OR      (   start_date  > to_date('20000101','YYYYMMDD')
            AND end_date    < to_date('20000101','YYYYMMDD')
            )I said "something like this" because I don't know what you really want to do.

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

  • Filter in business model using case when

    Dear Gurus,
    I have written this syntax on business logical layer WHERE CLAUSE:
    case  when 'All' = 'All' then upper(substring(Fact_Medication.DOCUMENT_ID_EXT from 1 for 3))
    else 'All' end
    *= upper(substring(Fact_Medication.DOCUMENT_ID_EXT from 1 for 3)*
    But, it was take too long to appear in dashboard, I'm afraid the syntax not proper.
    Does anyone know how to show all the data in oracle pl sql / obiee syntax ?
    I mean in Microsoft SQL we can use this Select * from A where column=''
    Please help this is urgent
    Regards
    JOE

    Hi,
    Thank for reply.
    This is my syntax (Revised):
    case when VALUEOF(NQ_SESSION."LOGIN")= 'All' then upper(substring(Fact_Medication.DOCUMENT_ID_EXT from 1 for 3))
    else VALUEOF(NQ_SESSION."LOGIN") end
    = upper(substring(Fact_Medication.DOCUMENT_ID_EXT from 1 for 3)
    I want if Login variable='All' then show all data, if not then show specific data.
    I though my query is right but it takes too long to appear in dashboard.
    Please help
    Regards
    JOE

  • Loop  wirh for using case when

    Hello,
    i wanna use a loop over a select
    but this select depend on a variable value
    so, here is what i did:
    CREATE OR REPLACE Procedure dispatch_pat(perId in number,shortlist_ID in number,orId in number, typeDonnee in number) is
    orVar number(7);
    test number;
    begin
    for orVar in (case when (orId <> 0) then (select OR_ID as id from ordre_regrpmt where or_id=orId) else (select OR_ID as id from ordre_regrpmt where or_id in ( select or_id from DETAIL_SHORT_LIST where ORSHORTLIST_ID=shortlist_ID)) end) loop
    select count(*) into test from ajust_pat where (OR_ID=orVar) and (PER_ID=perId);
    if (test=0) then
    insert into ajust_pat (OR_ID,PER_ID,GENE_ID) values (orVar.id,perId,typeDonnee);
    end if;
    end loop;
    end;
    but i got this error :
    On line: 5
    PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    Regards
    Sallemel

    Try this code
    /* Formatted on 2009/03/06 08:23 (Formatter Plus v4.8.8) */
    CREATE OR REPLACE PROCEDURE dispatch_pat (
       perid          IN   NUMBER,
       shortlist_id   IN   NUMBER,
       orid           IN   NUMBER,
       typedonnee     IN   NUMBER
    IS
       orvar   NUMBER (7);
       TEST    NUMBER;
    BEGIN
       IF orid = 0
       THEN
          FOR orvar IN (SELECT or_id AS ID
                          FROM ordre_regrpmt
                         WHERE or_id = orid)
          LOOP
             SELECT COUNT (*)
               INTO TEST
               FROM ajust_pat
              WHERE (or_id = orvar) AND (per_id = perid);
             IF (TEST = 0)
             THEN
                INSERT INTO ajust_pat
                            (or_id, per_id, gene_id
                     VALUES (orvar.ID, perid, typedonnee
             END IF;
          END LOOP;
       ELSE
          FOR orvar IN (SELECT or_id AS ID
                          FROM ordre_regrpmt
                         WHERE or_id IN (SELECT or_id
                                           FROM detail_short_list
                                          WHERE orshortlist_id = shortlist_id))
          LOOP
             SELECT COUNT (*)
               INTO TEST
               FROM ajust_pat
              WHERE (or_id = orvar) AND (per_id = perid);
             IF (TEST = 0)
             THEN
                INSERT INTO ajust_pat
                            (or_id, per_id, gene_id
                     VALUES (orvar.ID, perid, typedonnee
             END IF;
          END LOOP;
       END IF;
    END;
    /

Maybe you are looking for

  • Apple TV2 streaming via Airplay. No picture, but sound

    Internet ok, Youtube ok, but streaming from iPad 2 via Airplay to TV 2 is only sound, no picture

  • Need advise with upgrading T61P

    Hi Community I got a Lenovo T61p 6463-4YG Just upgraded with 8GB RAM and Intel SSD 520series 240GB, and got a Intel Core 2 Extreme X9000 2.8Ghz/6MB cache, coming Next week. The T61P only got the Intel on-board graphic card...Sadly The PCI-E slot is e

  • How to view BIW  data in XML format

    hi guys ...              just wondering if it is possible to view BIW data in XML format ,if yes how .                     I am looking to pass this  XML formatted data in to another server. venkat

  • SUN Cluster 2.2 behaviour when remoing SCSI

    We're running a SUN Cluster 2.2 , 2 node cluster on a SUN E5500 running Solaris 5.8 and Veritas VM. A1000 Boxes cross connected over SCSI to each node and D1000 dual attached per node. What would one as cluster behaviour expect if one Node crashes, p

  • Help me on below error

    Hi All, I  am working on popular items, there is an requirement  .Before saving my data into the system I need to clear my database for this I have written store procedure in xml. Please see below code and error. 1) method in java class public void c