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

Similar Messages

  • 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

  • Data missing in Crosstab report with calculated field via case when

    I use the Oracle 10g discoverer. When I create a crosstab report with a calculate field via function case when and put it as datapoint, some of the data is not showing. I tried to not use the case when function for the calculate field, then all the data show.
    I really do not the reason. Could anybody help me out with many thanks?

    Let me explain more.
    I have the original data below.
    Work order, Team, Hours_worked, date
    800001, S1, 5, 2012/01/01
    800001, S1, 15, 2012/01/10
    800001, S2, 4, 2012/01/04
    800002, S1, 3, 2012/01/15
    There are multipul records for the same work order, team on the same day or different.
    Finally I want to set the start date and end date as the parameter to create a crosstab report format like
    start date>=2012/01/01 and close date<=2012/01/05
    Team
    Total hours total hours within the range
    Work order S1 S2 ... S1 S2 ...
    800001 20 4 5 4
    800002 3 0 0 0
    in order to do it, I create two parameters independently start date and close date. Then I create a calculate field hours_worked_withinrange via
    Case when date>=:start date and date<=:end date then Hours_worked else 0 end
    This calculated field is correct in the tabular format report in discoverer desktop. But when I duplicate the list as crosstab. Some data is missing in crosstab data point.
    I checked once I change the calculate field defination not use case when. (For example, C1=hours_worked*2). Then everything runs correct.

  • 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

  • Evaluate Function in case when

    hi,
    i want to use evaluate function in case when statement.My req is
    if report_date=8/31 and sales_qty>30....show 1
    if report_date=7/15 and sales_qty>39...show 2..
    in the formula section i am using
    case WHEN "Fact- table"."Report  Date"=evaluate('to_date(%1%2)',"Column_name",'DD/MM
    /YYYY')) AND "Fact-table"."Sales_qty">30 THEN '1'  ELSE '0' END Report date data type is date only...Its giving an error date format is not supported
    Please help me out!!

    hi,
    thanks for u r quick response,i tried the code what u sent by its giving the error
    A general error has occurred. [nQSError: 42015] Cannot function ship the following expression: Evaluate( to_char(%1,%2),cast(D1.c7 as DATE ) , 'MM/DD/YYYY') ADa.....
    I tried in sql its giving correct results
    SELECT * FROM table WHERE report_month=To_Date('15/09/2009','dd/mm/yyyy')
    how to use the same in obiee?
    thanks
    Edited by: saichand on Oct 26, 2009 3:17 PM

  • MIN function iside CASE WHEN

    Hi gurus,
    I am new to PL SQL and wanted to know that cant we put MIN inside the CASE WHEN.
    I have following mentioned query:
    It is not allowing me to execute it, can anyone help me out?
    SELECT A,
    B,
    D,
    E,
    F,
    SUM
    (CASE
    WHEN <Expression> THEN (CASE
    WHEN ( <Expression>
    THEN 0
    ELSE min(<Expression>) or min(<Expression>)
         END
    ELSE 0
    END
    ) AS sales
    FROM tab1
    WHERE ( column1 = 'x' )
    GROUP BY A,
    B,
    D,
    E,
    F,
    Edited by: user11001347 on Oct 29, 2009 2:34 AM

    Group functions within a case are perfectly acceptable e.g.
    select sum(case when dummy = 'X' then '1' else min(dummy) end) from dual group by dummy
    SUM(CASEWHENDUMMY='X'THEN'1'ELSEMIN(DUMMY)END)
                                                 1There are other problems with your code...
    This looks wrong to me:
    min(<Expression>) or min(<Expression>)and you have a trailing comma after F in the group by clause.
    When you're having problems with a piece of SQL, It's useful to us if you post the error you are getting back, and your table structure and sample test data too if possible.
    Edited by: Cyn on Oct 29, 2009 9:43 AM

  • Using CASE WHEN in PL/SQL package

    I am trying to convert the values in a selected column into 1 and 0 so that I can display all 1s in one column, all 0s in another. I am doing this in a PL/SQL package. However ORACLE compiler does not like the CASE construct.
    Does anyone know how to group values in a column into several new columns. If CASE WHEN construct is not doable in PL/SQL, what alternatives are there? Thanks.
    /******* My package starts here *******/
    CREATE OR REPLACE PACKAGE TEST_NEED AS
    PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2);
    END CVRR_MON_NEED;
    CREATE OR REPLACE PACKAGE BODY TEST_NEED
    AS
    PROCEDURE procTEST_NEED(STARTING_DATE IN VARCHAR2)
    IS
    TEST_START DATE := TO_DATE(STARTING_DATE,'MM/DD/YYYY');
    CURSOR v_Cursor IS
    SELECT A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID,
    SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 > 40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND B.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0 END) QUALIFIED
    FROM A, B, C, D
    WHERE A.ID = B.B_ID
    AND RTRIM(A.P_CODE) = C.P_CODE
    AND A.P_ID = D.P_ID
    AND A.P_ID < 99999999999999999999
    AND A.E_DATETIME < SYSDATE
    GROUP BY A.D_CODE, A.M_CODE, TEST_START , C.C_NAME,C.P_ID;
    v_RecordHolder v_Cursor%ROWTYPE;
    BEGIN
    OPEN v_Cursor;
    FETCH v_CursorINTO v_RecordHolder ;
    WHILE v_Cursor%FOUND LOOP
    look for records in another table with matching keys of the cursor
    if found then update by incrementing the existing values in the matching records with values of the current currsor row
    else insert the current cursor row
    FETCH v_Cursor INTO v_RecordHolder ;
    END LOOP;
    END procTEST_NEED;
    END TEST_NEED;

    I am trying to convert the values in a selected
    column into 1 and 0 so that I can display all 1s in
    one column, all 0s in another. I am doing this in a
    PL/SQL package. However ORACLE compiler does not
    like the CASE construct.
    Does anyone know how to group values in a column into
    several new columns. If CASE WHEN construct is not
    doable in PL/SQL, what alternatives are there?
    Thanks.
    CURSOR v_Cursor IS
    SELECT A.D_CODE, A.M_CODE, TEST_START ,
    , C.C_NAME,C.P_ID,
    SUM(CASE WHEN MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
    40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 ANDB.B_CODE IN '11.1','222.2','272.4') THEN 1 ELSE 0
    END) QUALIFIEDUse the Decode function. This has been around in oracle SQL for ages and works like a case construct.
    You would do something like
    select ...
    sum( decode (MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 >
    40 AND MONTHS_BETWEEN(SYSDATE, D.P_DOB)/12 <85 AND
    B.B_CODE IN ('11.1','222.2','272.4') 1,0 )

  • Help in changing plsql case when to decode

    Hi,
    Can anyone help me to change this sql for it to use decode function instead of case when? Below is the sql code
    Thanks in advance.
    SELECT
    parts,
    weeks,
    SUM(qty) qty
    FROM (
    SELECT
    CASE
    WHEN ((is_tbd = 'yes' AND is_tbd_order = 'no') OR ex_fac_date > v_asofdate + 131) THEN 'tbd'
    WHEN ex_fac_date BETWEEN v_asofdate - 1 AND v_asofdate + 5 AND is_tbd = 'no' THEN 'wk1'
    WHEN ex_fac_date BETWEEN v_asofdate + 6 AND v_asofdate + 12 AND is_tbd = 'no' THEN 'wk2'
    WHEN ex_fac_date BETWEEN v_asofdate + 13 AND v_asofdate + 19 AND is_tbd = 'no' THEN 'wk3'
    WHEN ex_fac_date BETWEEN v_asofdate + 20 AND v_asofdate + 26 AND is_tbd = 'no' THEN 'wk4'
    WHEN (ex_fac_date < v_asofdate - 1) AND is_tbd = 'no' THEN 'past_due'
    END weeks,
    ffdate,
    parts,
    SUM(qty) qty
    FROM
    delivery)

    I can't use case because my oracle is 8i,Please join 21st Century
    Can you help me checnge this to if then elsif insteadSQL does does contain IF statement!

  • Discoverer: "CASE WHEN...." in calculations won't show anything in GUI !?!?

    Hi all!
    I have a report in Discoverer Plus (Version 10.1.2.48.18) which contains 2 columns: One with actual spendings and one with budget figures. I want to make a third column which holds actual spendings in percentage of the budget. To do this, I need to make a calculation similar to:
    CASE WHEN SUM(budget) <> 0 THEN SUM(spendings)/SUM(budget) ELSE NULL END
    However, when I apply this calculation to the third column, my report don't return any numbers at all in any column.
    What am I doing wrong? -- Is this a bug, and how should I solve my problem?
    ~Morten

    I can get something out if I do this (applying an aggregate function to it all):
    SUM(CASE WHEN budget <> 0 THEN spendings/budget ELSE NULL END)
    However, this is wrong (Summarizing these percentages doesn't give any meaning).
    SQL lookes something like this:
    SELECT /*+ NOREWRITE */ o100448.ACCOUNT as E100451,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) as E101004,MAX(o100448.ACCOUNTNUM) as as100473_100451_NEW,CASE WHEN ( SUM(o100862.BUDGET) ) <> 0 THEN ( SUM(o100862.AMOUNT) )/( SUM(o100862.BUDGET) ) ELSE NULL END as C_1,( SUM(o100862.BUDGET) )*o100448.SIGN as C_3,( SUM(o100862.AMOUNT) )*o100448.SIGN as C_2,GROUPING_ID(o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM')))) as GID
    FROM TANGO.TANGO_ACCOUNTS o100448,
    TANGO.TANGO_SUMS o100862
    WHERE ( (o100862.ORG = o100448.ORG AND o100862.ACCOUNTNUM = o100448.SUBACCOUNTNUM))
    AND (o100448.ACCOUNTNUM BETWEEN 30000 AND 79999)
    AND (o100862.DIM = '50')
    AND (o100448.ORG = 'bru')
    GROUP BY GROUPING SETS(( o100448.ACCOUNT,o100448.SIGN,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ),( o100448.ACCOUNT,(decode((ADD_MONTHS(o100862.DATE1,-4)),null,to_date(null, 'MMDDYYYY'),to_date(to_char(trunc((ADD_MONTHS(o100862.DATE1,-4)),'YYYY'),'YYYY') || '01','YYYYMM'))) ))
    HAVING (GROUP_ID()=0)
    ORDER BY GID DESC;
    I tried to fire this SQL up in TOAD (or whatever SQL-tool you might have), and columns C_2 and C_3 are empty. Seems like I'm doing something awfully wrong here.....
    Any ideas? (There must be some SQL sharks out there ;-p)
    ~Morten

  • Font issues when in preview or publishing project (Captivate 4)

    I am continuing to experience problems with fonts in my projects.
    As a standard, I am only using Verdana 11 pt and 10 pt in my slides. This standard/consistancy is quite evident when I am viewing the slides in edit view. However, when I preview or publish the project, the text from slide to slide is not consistant.
    It appears as through some slides display Vendana slightly squished... it is clearly Vendana just reduced in height. I have tried various options, such as setting the quality mode and so far,nothing has helped.
    Please see the attachment, which should better illustrate what I am describing. Each of the five 100% cropped screen captures are from separate slides and I have combined them into one jpg.
    Any ideas?

    Hi Shawn
    Sorry I didn't see this before you went to the trouble of deleting the dat file. I would have speculated this would have had no difference whatsoever.
    It's common to see folks report issues with Transparent captions. Normally the report is that the captions are "blurry" or "fuzzy". Usually it's because of anti-aliasing. There are ways past it.
    Fellow Adobe Community Expert Paul Dewhurst initially discovered that if you simply highlight one blank character using the color #C0C0C0 the caption would render without anti-aliasing.
    Later we discovered that if the caption had a bullet point anywhere in the text, it would render without anti-aliasing. That seems simpler to me than using the highlight. What you do is just add a few blank lines, apply the bullet to the last line, then size the caption so you don't see the bullet. (assuming, of course, that you had no bullets elsewhere. In that case it would be unnecessary to do this)
    The Captivate developers added in an option where you may enable/disable anti-aliasing globally. This is done via Edit > Preferences > Project > SWF Size and Quality.
    Hopefully something there was helpful... Rick
    Helpful and Handy Links
    Captivate Wish Form/Bug Reporting Form
    Adobe Certified Captivate Training
    SorcerStone Blog
    Captivate eBooks

  • Another case when statement

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

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

  • CASE WHEN THEN END

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

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

  • Use of when function with linking sheets

    Hello,
    So I went through the Manual and the Forum.
    There is no German Forum so WENN means IF and WAHR means TRUE;
    If I enter this function:
    =WENN(G6=WAHR;"=Blatt 3 :: Tabelle 1 :: B6";"nix")
    it respondes in case of RIGHT the string "Blatt 3 :: Tabelle 1 :: B6"
    but should take the value (Date in this case)! If i use just
    =Blatt 3 :: Tabelle 1 :: B6
    whitout when function,
    it responses fine the Date of the refered sheet respective matrix respective cell, in this case 05.01.2006 (whatever:)
    Has anyone a clue what´s going on ??
    Thanks in advanced

    Ananas,
    It appears that your formula contains three extra characters: "= and "
    Try: =WENN(G6=WAHR;Blatt 3 :: Tabelle 1 :: B6;"nix")
    By the way, thanks for the translations.
    pw

  • SELECT CASE WHEN not working?

    Hello, can't figure out why the following statement continues to return NULL values and seems to not recognize my case when portion?...
    INSERT tbl_Main
    select OrderID
     ,(select
      case
       when (b.OrderValue is null or b.OrderValue = '') then 'Y'
       else b.OrderValue
      end
     from tbl_OrderDetails b where b.OrderID = a.OrderID and b.DetailID = '7')
    AS OrderStatus
    from tbl_Order a
    Thanks in advanced.

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. Temporal data should
    use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. 
    1. The use of the “tbl-” prefix is a design flaw called “tibbling” and people will laugh at you for it. 
    2. Do not nest selects inside a select list; the performance stinks. 
    3. Why do you think “A”, "D” etc are good aliases that will make maintaining this code easier? Noobs do this is match the names of tape drives on old hardware! 
    4. Why do you think that treating a NULL and an empty string as the same is a good idea? Use a CHECK (order_value <> ''). 
    My guess is you could write this instead: 
    INSERT INTO Orders
    SELECT order_id, COALESCE (D.order_value, 'Y') AS order_status
     FROM Order_Details AS D 
    WHERE D.order_id = Orders.order_id 
      AND D.detail_id = '7')
    AS order_status; 
    But this still smells bad. A status is a state of being so it has a temporal component. Order details do not usually have an id; the item identifier (EAN, UPC, SKU, or whatever) is used. 
    --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

  • Case when

    hello
    what wrong with this query...
    1 SELECT COUNT(*) FROM AGR_MSTR WHERE (CASE WHEN 1=1 THEN
    2 'AGR_STATUS='||CHR(39)||'L'||CHR(39)
    3 ELSE
    4 'AGR_STATUS='||CHR(39)||'P'||CHR(39)
    5* END)
    6 /
    END)
    ERROR at line 5:
    ORA-00920: invalid relational operator
    executed perfectly if i run same query in select clause,
    SELEct (CASE WHEN 1=1 THEN
    'AGR_STATUS='||CHR(39)||'L'||CHR(39)
    ELSE
    'AGR_STATUS='||CHR(39)||'P'||CHR(39)
    END) from dual

    SQL> select count(*)
      2    from emp
      3   where (case when 1=1 then 'job='||chr(39)||'CLERK'||chr(39)
      4          else 'job='||chr(39)||'MANAGER'||chr(39)
      5          end)
      6  /
            end)
    FOUT in regel 5:
    .ORA-00920: invalid relational operatorThis doesn't work because basically you are saying "select count(*) from emp where <function>". You can have a function in the where clause, but it should be a boolean predicate like in "select count(*) from emp where <function> = <value>".
    SQL> select (case when 1=1 then 'job='||chr(39)||'CLERK'||chr(39)
      2          else 'job='||chr(39)||'MANAGER'||chr(39)
      3          end)
      4    from dual
      5  /
    (CASEWHEN1=1T
    job='CLERK'
    1 rij is geselecteerd.So the function itself is OK.
    SQL> select count(*)
      2    from emp
      3   where (case when 1=1 then 'job='||chr(39)||'CLERK'||chr(39)
      4          else 'job='||chr(39)||'MANAGER'||chr(39)
      5          end) = 'job=''CLERK'''
      6  /
                                  COUNT(*)
                                        14
    1 rij is geselecteerd.Now it is of the form "where <function> = <value>" and it returns results.
    But you probably need this one:
    SQL> select count(*)
      2    from emp
      3   where job = case when 1=1 then 'CLERK' else 'MANAGER' end
      4  /
                                  COUNT(*)
                                         4
    1 rij is geselecteerd.Regards,
    Rob.

Maybe you are looking for

  • Itunes freezes when streaming music to airport express and to loewe air speaker at the same time?

    Hi, (first post ) I was recently offered a Loewe Airspeaker. I already had an Airport Express connected to a hi-fi system. The Airport Express + hi-fi is in the living-room and the Loewe Airspeaker is in our bedroom. Both are connected to my network

  • Trying to intall Adobe Air on Windows 7 Home Premium

    I successfully install Adobe Air, then there is no sign of the program anywhere even though it shows up to uninstall it in the control panel.  You cannot find it under a search or on the program list.  The only file that shows up is the adobe air ins

  • Why do I get an error?

    Hello, What I want is for a new row to be inserted each time the last column has finished being edited. I add the data in each row to a Vector() after every row. I get an ArrayIndexOutOfBoundsException when I want to insert a new row. Do you know why

  • Foreign currency  invoice not shown in local currency

    Dear Experts , Can you please help me to resole In my company code currency is INR and my foreign currency is USD , when i posted a invoice in foreign currency it shows in print preview only in foreign currency that is USD but i want to see the local

  • Display resolution on ATI Radeon 7500

    Just bought a LG 22" which runs 1650x1050 native resolution (WSXGA+) and although the dropdown box in XP says I'm there I'm really not. The fonts are obviously wider than they should be,images that are 1650x1050 require scrolling, etc. Any idea what