CASE in a WHERE clause : ORA-00905

Hi everyone,
I am trying to use a CASE in a WHERE clause and I got the error ORA-00905: missing keyword. Here is my code :
SELECT id_reserv,
     concat(nom,concat('_',indice)) as nom,
     libelle,
     num_lot,
     resa_keyword1,
     resa_keyword2,
     resa_keyword3,
     resa_keyword4,
     date_creation,
     comm_creation,
     id_util,
     actif,
     id_env_act,
     (SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util,
     (SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env,
     (SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp,
     (SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif
FROM reservation r
     WHERE r.nom NOT LIKE 'RESERV_LOT_%'
     AND id_util='1'
     AND actif='1'
     AND id_env_act>='-1'
     AND CASE sansdemande
     WHEN true THEN id_reserv not in select id_reserv from demande_livraison where id_env_dep>='-1'
     ELSE id_reserv=id_reserv
     END
     AND nom LIKE '%'
ORDER BY date_creation;
I already looked at the CASE statement and it seems that the syntax is correct, so I'm not sure I can use it in a WHERE clause.
Any help would be nice !
Guich

Hi,
it should be something like this:
AND CASE
  WHEN 'false'='true' THEN (select id_reserv from demande_livraison where id_env_dep>='-1')
  ELSE id_reserv
     END = id_reserv The subquery should give one row back
But I think it is better to write your query as:
SELECT id_reserv,
     concat(nom,concat('_',indice)) as nom,
     libelle,
     num_lot,
     resa_keyword1,
     resa_keyword2,
     resa_keyword3,
     resa_keyword4,
     date_creation,
     comm_creation,
     id_util,
     actif,
     id_env_act,
     (SELECT login from utilisateur u where u.id_util=r.id_util) AS nom_util,
     (SELECT nom from environnement e where e.id_env=r.id_env_act) AS nom_env,
     (SELECT count(*) from reserv_comp rc where rc.id_reserv=r.id_reserv) AS nbComp,
     (SELECT count(*) from reserv_modif mc where mc.id_reserv=r.id_reserv) AS nbModif
FROM reservation r
     WHERE r.nom NOT LIKE 'RESERV_LOT_%'
     AND id_util='1'
     AND actif='1'
     AND id_env_act>='-1'
     AND
                      (  'false'='true' and id_reserv not in (select id_reserv from demande_livraison where id_env_dep>='-1')
                      or
                      ( 'true'= 'true' and id_reserv=id_reserv
     AND nom LIKE '%'
ORDER BY date_creation;This coding in SQL something as if a=b then c, else d in the simplest form.
Herald ten Dam
http://htendam.wordpress.com

Similar Messages

  • Case statement in where clause ??

    Hello gurus,
    Can we use case statements in where clause ?? Any example will be great!
    And also i would like to know, besides CASE and DECODE statements, Is there any way we can use IF ELSE statements in SELECT clause or in WHERE clause ?
    Thank you!!

    Hi,
    user642297 wrote:
    Hoek,
    Thanks for the reply
    Whatever you return from 'then' should match your criteria.I didnt get this part...can you elaborate this part ?? Thank you!!Remember what a CASE expression does: it returns a single value in one of the SQL data types (or NULL).
    You're probably familiar with conditions such as
    WHERE   col = 1Inthe example above, col could be replaced by any kind of expression: a function call, and operation (such as "d * 24") or a CASE expression, which is exactly what Hoek posted:
    where  case
             when col = 6 then 1
             when col = 9 then 1
           end = 1;I think what Hoek meant about mnatching was this: since the CASE expression is being compared to a NUMBER, then every THEN clause (as well as the ELSE, if there is one) should return the same data type. You can't have one THEN clause return a NUMBER, and another one in the same CASE expression return a DATE, like this:
    where  case
             when col = 6 then 1
             when col = 9 then SYSDATE     -- WRONG! Raises ORA-00932: inconsistent datatypes
           end = 1; 
    By the way, it's rare when a CASE expression really helps in a WHERE clause. CASE is great for doing conitional stuff in places where you otherwise can't (in the ORDER BY clause, for example), but the WHERE clause was designed for conditions.
    Hoek was just trying to give a simple example. If you really wanted those results, it would be simpler to say:
    where  col = 6
    or     col = 9and simpler still to say
    where  col  IN (6, 9)

  • How to use CASE stmt in Where clause

    Hi,
    How to use CASE stmt in WHERE clause?. I need the code. Please send me as early as possible..........

    Hi,
    1004977 wrote:
    Hi,
    How to use CASE stmt in WHERE clause?. There's no difference between how a CASE expression is used in a WHERE clause, and how it is used in any other clause. CASE ... END always returns a single scalar value, and it can be used almost anywere a single scalar expression (such as a column, a literal, a single-row function, a + operation, ...) can be used.
    CASE expressions aren't needed in WHERE clauses very much. The reason CASE expressions are so useful is that they allow you to do IF-THEN-ELSE logic anywhere in SQL. The WHERE clause already allows you to do IF-THEN-ELSE logic, usually in a more convenient way.
    I need the code.So do the peple who want t help you. Post a query where you'd like to use a CASE expression in the WHERE clause. Post CREATE TABLE and INSERT statements for any tables used unless they are commonly available, such as scott.emp). Also, post the results you want from that sample data, and explain how you get those resuts from that data.
    See the forum FAQ {message:id=9360002}
    Please send me as early as possible..........As mentioned bfore, that's rude. It's also self-defeating. Nobody will refuse to help you because you don't appear pushy enough, but some people will refuse to help you if you appear too pushy.

  • Case statement within where clause

    How can i write a case statement within Where clause of SQL statement.
    Ex:
    If sysdate is less than Dec 31 of 2009 then run the query for 2009 else run the query for 2010.
    belwo query is not working. Please let me know how can i write a case statement within where clause.
    Select * from table
    where
    Case
    when to_char(sysdate,'yyyymmdd')<=20091231 then tax_year=2009
    else tax_year=2010
    End

    Hi,
    You can get the results you want like this:
    Select  *
    from      table
    where   tax_year = Case
                      when  to_char(sysdate,'yyyymmdd') <= 20091231
                      then  2009
                      else  2010
                 End
    ;A CASE expression returns a single value in one of the SQL data types, such as a NUMBER, VARCHAR2 or DATE. There is no boolean type in SQL.

  • Case with where clause - ORA-00920: Invalid relational operator

    Hi All, when I try to run the query below, I get the following error...
    ORA-00920: invalid relational operator
    00920. 00000 -  "invalid relational operator"
    *Cause:   
    *Action:
    Error at Line: 16 Column: 5
    Does anyone know what's wrong with my query? thanks in advance.
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END as "MonthNo"
    ORDER BY CONCAT (year,"MonthNo") DESC

    The problem is the as "MonthNo" - you can't give an "AS" alias to an expression in a where clause.
    You have not actually given any condition, just a set of translations from period into a number.
    You also haven't said what you're trying to do.
    Perhaps you want:
    SELECT concat (year,period)
    FROM DD_ACTUALS_FACT
    WHERE something
    ORDER BY CONCAT (year, CASE Period
    WHEN 'JAN' THEN '01'
    WHEN 'FEB' THEN '02'
    WHEN 'MAR' THEN '03'
    WHEN 'APR' THEN '04'
    WHEN 'MAY' THEN '05'
    WHEN 'JUN' THEN '06'
    WHEN 'JUL' THEN '07'
    WHEN 'AUG' THEN '08'
    WHEN 'SEP' THEN '09'
    WHEN 'OCT' THEN '10'
    WHEN 'NOV' THEN '11'
    WHEN 'DEC' THEN '12'
    END  ) DESC

  • No output for XML Publisher Report using CASE/DECODE in Where Clause

    Hi,
    I've a business requirement to modify an existing report which has two input parameters,
    -> p_statcode (Closed Status) which can have values 'Y' or 'N'
    -> p_overdue (Overdue Flag) which can have values 'Y' or 'N'
    The Overdue Flag is an evaluated column having values of Y/N and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                            overdue_flagThe user requirement now is they needs to be a third option for parameter p_overdue called ALL,
    passing which the output should include records having
    p_statcode is Y ELSE p_statcode is N AND p_overdue is Y OR p_overdue is N
    In other words records having both Y and N vlaues for Overdue Flag have to be returned irrespective of the value given to Closed Status.
    Original where clause in the Data Definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)My modified code is as follows,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)Both approaches have the same problem.
    The output is in EXCEL format. The modified query works fine for p_overdue as Y or N but when p_overdue is passed as ALL it returns an empty EXCEL sheet with just the report output column headers.
    Any help as to why this is the case ?? What is wrong in my approach ?
    Regards,
    Vishal

    not clear about p_overdue = ALL
    which values needed for p_overdue = ALL ?
    try smth like
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )for overdue_flag which has more then 'Y', 'N' values
    if overdue_flag only in ('Y','N') then
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )

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

  • How to use case function in where clause

    Hi,
    Suppose a table DEMO has columns
    DEMO TABLE
    user_id
    user_name
    location
    In this table i have 15 users. but out of 15 users i want to use only 5 users for passing as user_name.
    then how to achieve the result
    1. when i pass the particular 5 user_name in where clause then i should get all the user_name and for other 10 users it will show only the passing user_name.
    how to use case function

    Do you mean this ?
    SQL> var name varchar2(10)
    SQL> exec :name := 'ALLEN'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> exec :name := 'SMITH'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    14 rows selected.
    SQL> exec :name := 'BLAKE'
    PL/SQL procedure successfully completed.
    SQL> select ename from emp where case when :name in ('SMITH','ALLEN') then ename
      2  else :name end = ename;
    ENAME
    BLAKERgds.

  • Case function in where clause

    i insert the below rows in a table cash_book.
    PRJ_CODE PRJ_NAME
    1203 SHIFA
    1203 SHIFA
    1203 SHIFA
    1202 FATIMA
    1202 FATIMA
    1203 SHIFA
    if i select 1202 code then return 1202 code rows, if i select 1203 then returns 1203 code rows, if i select other than both values then returns all rows. how can i define in one query with use (case or decode function) in where clause ??

    perhaps something like this:
    create table test
    as
    select 1200 + rownum prj_code
      from dual
    connect by level <= 10;
    select * from test;
      PRJ_CODE
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    var v_PRJ_CODE number
    exec :v_PRJ_CODE := 1200;
    select *
      from test
    where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
      PRJ_CODE
          1201
          1202
          1203
          1204
          1205
          1206
          1207
          1208
          1209
          1210
    exec :v_PRJ_CODE := 1203;
    select *
      from test
    where PRJ_CODE = :v_PRJ_CODE
        or 1 = case when :v_PRJ_CODE in (1202, 1203) then 0 else 1 end;
      PRJ_CODE
          1203Regards
    Martin

  • Case expression in where clause

    I have requirement to select a columns based on condition Datacode should (when the column id=1 THEN 'GILL' ELSE WHEN ID=11 THEN IT Should be 'HEL'
    how can i write in case statment
    AND DATA_CD =CASE WHEN  ID=1  THEN 'GIL'
                             WHEN  ID=11 THEN 'HEL'
                        END ) my question is above code is corrrect for where clause?
    what happens to the ELSE PART?
    Please clarify
    S

    oraclehema wrote:
    I have requirement to select a columns based on condition Datacode should (when the column id=1 THEN 'GILL' ELSE WHEN ID=11 THEN IT Should be 'HEL'
    how can i write in case statment
    AND DATA_CD =CASE WHEN  ID=1  THEN 'GIL'
    WHEN  ID=11 THEN 'HEL'
    END ) my question is above code is corrrect for where clause?
    what happens to the ELSE PART?It is for you to tell what happens to the ELSE part.
    If the ID is not 1 or 11, then your AND condition fails and probably your query will not retrieve any records for you (Assuming this query is not a part of OR condition, because there is no query provided.).
    Because, without ELSE, the default shall be set to NULL and since you used "DATA_CD =", NULL shall not equate with it resulting in failure of condition. Hence, I would suggest you to add some default value in the ELSE part.

  • Case statement with where clause.

    I appreciate that there are much simpler ways to run this query but I wondered if anyone else had come across the following -
    select distinct
    product_table.a,
    product_table.b,
    product_table.c,
    CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'     
    WHEN product_table.b = 'B' THEN 'BBB'
    WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
    WHEN product_table.b IN ('D','DD') THEN 'DDD'
    WHEN product_table.b LIKE 'E%' THEN 'EEE'
    WHEN product_table.b LIKE 'F%' THEN 'FFF'
    WHEN product_table.b LIKE 'G%' THEN 'GGG'
    ELSE 'UNKNOWN' END
    from product_table                    
    where
    ( CASE WHEN product_table.c IN ('A','AA') THEN 'AAA'     
    WHEN product_table.b = 'B' THEN 'BBB'
    WHEN product_table.c IN ('C','CC','CCC') THEN 'CCC'
    WHEN product_table.b IN ('D','DD') THEN 'DDD'
    WHEN product_table.b LIKE 'E%' THEN 'EEE'
    WHEN product_table.b LIKE 'F%' THEN 'FFF'
    WHEN product_table.b LIKE 'G%' THEN 'GGG'
    ELSE 'UNKNOWN' END) = 'FFF'
    when this query runs its as if the where clause = 'FFF' does not exist and all rows are returned.
    Thanks, Sarah.

    Technical questions should be addressed to one of the technical forums. You'll probably find that the folks in the PL/SQL forum (Products | Database | PL/SQL) have some thoughts.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • How to use a case statement in where clause

    Hi All,
    I have a requirement which is to bring all the claims that are created in the last month.So, i wrote a query something like this
    select * from claims
    where
    (Month(ClaimOpenDate) = Month(Getdate())-1 and year(claimopendate) = year(getDate()))
    which would give me any new claims created in last month of current year, but this condition fails if we are in the first month of a new year( lets say if we are in 2016 jan then month(getdate())-1 would be 0 and year(getdate()) would be 2016 so we dont
    find any records where year is 2016 and month is 0 for claimopen).
    So, i would like to use a case statament or something which can help me get around this one.
    Can someone please help me with any suggestions?
    Thanks

    Hi Jason,
    Thanks a lot for your help. This is what exactly i am looking for but i just gave a sample query above below is my original query 
    select
    row_number() over (order by [ClaimNumber]) as DataElementName
    ,c.PolicyNumber as PolicyNum
    , c.FirstName as CustNameF
    ,c.LastName as CustNameL
    ,c.PolicyForm as PolType
    ,'Homesite' as Company
    ,[ClaimNumber] as ClaimNum
    ,E.office as Ofc
    ,e.Supervisior_FullName as Team
    , RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
    , case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
    ,e.AdjusterID as RepC -- not sure
    ,CONVERT ( varchar,c.LossDate ,101) as DOL
    ,convert (varchar,c.ClaimOpenDate,101) as DOR
    ,rtrim(c.Loss_State) as LossSt
    ,c.Loss_ZipCode as LossZIP
    ,c.Loss_City as LossCity
    ,c.LossType as FOL
    ,'' as PR
    ,'' as PRNum
    ,1 as FeaNum
    ,'HO' as FeaType
    ,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
    ,'' as FeaOpen
    ,'' as FeaClosed
    ,s.PaymentIndemnityAmount as PaidAmt
    ,s.ReserveIndemnityAmount as Reserve
    ,'' as Sub
    ,'' as Sal
    ,'' as FeatOwnOfc
    ,e.Supervisior_FullName as FeatOwnTeam
    ,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
    ,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
    ,e.AdjusterID as FeatOwnRepCode
    ,NULL AS Description --not sure
    from [Stg].[HS_DW_RV_Claims] c
    inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
    inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
    left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
    where c.LoadSource = 'CMS'
    and
    (s.PaymentIndemnityAmount <>0 or s.PaymentExpenseAmount <>0)
    and
    ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
    UNION ALL
    select
    row_number() over (order by [ClaimNumber]) as DataElementName
    ,c.PolicyNumber as PolicyNum
    , c.FirstName as CustNameF
    ,c.LastName as CustNameL
    ,c.PolicyForm as PolType
    ,'Homesite' as Company
    ,[ClaimNumber] as ClaimNum
    ,E.office as Ofc
    ,e.Supervisior_FullName as Team
    , RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FORepF
    , case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FORepL
    ,e.AdjusterID as RepC -- not sure
    ,CONVERT ( varchar,c.LossDate ,101) as DOL
    ,convert (varchar,c.ClaimOpenDate,101) as DOR
    ,rtrim(c.Loss_State) as LossSt
    ,c.Loss_ZipCode as LossZIP
    ,c.Loss_City as LossCity
    ,c.LossType as FOL
    ,'' as PR
    ,'' as PRNum
    ,1 as FeaNum
    ,'HO' as FeaType
    ,case when rtrim(c.claimStatus)= 'Closed' then 'Closed' else 'Open' end as FeaStat
    ,'' as FeaOpen
    ,'' as FeaClosed
    ,s.PaymentIndemnityAmount as PaidAmt
    ,s.ReserveIndemnityAmount as Reserve
    ,'' as Sub
    ,'' as Sal
    ,'' as FeatOwnOfc
    ,e.Supervisior_FullName as FeatOwnTeam
    ,RIGHT(e.adjuster_Name ,LEN(e.adjuster_Name)- charindex(',' ,e.adjuster_Name)) as FeatOwnRepF
    ,case when charindex(',' ,e.adjuster_Name) <> 0 then left(e.adjuster_Name,charindex(',' ,e.adjuster_Name)-1) else e.adjuster_Name end as FeatOwnRepL
    ,e.AdjusterID as FeatOwnRepCode
    ,DESCRIPTION --not sure
    from Stg.IG_Document D
    inner join [Stg].[HS_DW_RV_Claims] c on D.PARENTREF = C.ClaimNumber
    inner join [dbo].[Claims_Primary_Adjuster] a on a.CLAIM_NUMBER = c.ClaimNumber
    inner join [dbo].[vw_Adjuster] e on e.adjuster_Name = a.primary_ADJUSTER
    left outer join [Stg].[HS_DW_LossClaimSummary] s on c.ClaimKey=s.ClaimKey
    where c.LoadSource = 'CMS'
    and
    DESCRIPTION like '%Denial Letter%'
    and
    ClaimOpenDate BETWEEN DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP) -1, 0) AND DATEADD(mm, DATEDIFF(mm, 0, CURRENT_TIMESTAMP), 0)
    So if i use your logic in the end for both the where clauses its been more than 10 minutes and the query is still running however if i use my old method it doesnt even take a second. Looks like its affecting the execution plan. Any suggestions to get around
    this one please?
    Thanks

  • Case satement in where Clause..

    Hi I haev issue facing in procedure there are 4 param as in put some time 2 parameter will have value and some time it is null and and one parameter has multiple value . and this value i am passing to cursor and cursor should return value even though value is null so using case satement in where clasue but it is throwing error.
    here syntax
    SELECT strategicinitiativeid, projectid, -- ltm, ltmdeptid,
    YEAR,
    SUM (netexpensebudget) netexpensebudget,
    SUM (devsoftcapbudget + purchasesoftcapbudget
    + hardwarecapbudget
    ) AS totalcapbudget,
    SUM (netexpensebudgetinprog) netexpensebudgetinprog,
    SUM ( devsoftcapbudgetinprog
    + purchasesoftcapbudgetinprog
    + hardwarecapbudgetinprog
    ) AS totalcapinprogbudget
    FROM vpendingprojectsaligntosi
    WHERE CASE
    WHEN v_projectid IS NOT NULL
    THEN projectid IN (v_projectid)
    END and case v_SIID is not null
    then strategicinitiativeid=v_SIID end
    AND budgetstepid IN (v_budgetstepid)
    GROUP BY strategicinitiativeid, YEAR, projectid;

    user13301356 wrote:
    Hi I haev issue facing in procedure there are 4 param as in put some time 2 parameter will have value and some time it is null and and one parameter has multiple value . and this value i am passing to cursor and cursor should return value even though value is null so using case satement in where clasue but it is throwing error.
    here syntax
    SELECT strategicinitiativeid, projectid, -- ltm, ltmdeptid,
    YEAR,
    SUM (netexpensebudget) netexpensebudget,
    SUM (devsoftcapbudget + purchasesoftcapbudget
    + hardwarecapbudget
    ) AS totalcapbudget,
    SUM (netexpensebudgetinprog) netexpensebudgetinprog,
    SUM ( devsoftcapbudgetinprog
    + purchasesoftcapbudgetinprog
    + hardwarecapbudgetinprog
    ) AS totalcapinprogbudget
    FROM vpendingprojectsaligntosi
    WHERE CASE
    WHEN v_projectid IS NOT NULL
    THEN projectid IN (v_projectid)
    END and case v_SIID is not null
    then strategicinitiativeid=v_SIID end
    AND budgetstepid IN (v_budgetstepid)
    GROUP BY strategicinitiativeid, YEAR, projectid;may be --untested
    SELECT strategicinitiativeid,
           projectid,
           YEAR,
           SUM(netexpensebudget) netexpensebudget,
           SUM(devsoftcapbudget + purchasesoftcapbudget + hardwarecapbudget) AS totalcapbudget,
           SUM(netexpensebudgetinprog) netexpensebudgetinprog,
           SUM(devsoftcapbudgetinprog + purchasesoftcapbudgetinprog +
               hardwarecapbudgetinprog) AS totalcapinprogbudget
      FROM vpendingprojectsaligntosi
    WHERE projectid in nvl(v_projectid, projectid)
       AND strategicinitiativeid in nvl(v_SIID, strategicinitiativeid)
       AND budgetstepid in (v_budgetstepid)
    GROUP BY strategicinitiativeid, YEAR, projectid

  • Case condition in where clause

    Hi
    I'm a SQL beginner but according to my reading of the manual, this syntax should be acceptable. I'm using it in application express but tested it also in SQL developer and finding that it fails with an "invalid relational operator" error, with the line number pointing to the ELSE clause of the CASE condition, but a column number pointing to white space.
    This is a nested select but that shouldn't matter. The fragment in question is this:
    select some columns
    from res
    where res.villaid = :P605_VILLAID
    and INSTR(:P604_RES_STATES, res.states) != 0
    and (CASE :P604_EXCLUDE_ZERO
    WHEN 'Y' THEN 'res.rate > 0'
    ELSE 'res.rate >= 0'
    END)
    and res.DEPARTDATE > :P605_STARTDATE
    and res.ARRIVEDATE <= :P605_ENDDATE,
    I hope this formats ok when posted. The code is looking for reservations in a date range (which works fine when the other conditions are commented out), and should only output zero-rate rows (complimentary nights) if the user asks for this in the P604_EXCLUDE_ZERO bind variable. There are probably other ways to go about this, but I am too stubborn to give up on this. Well, not yet anyway.
    Thanks and regards
    CS

    select some columns
      from res
    where res.villaid = :p605_villaid
           and instr (:p604_res_states, res.states) != 0
           and sign (res.rate) >= case when :p604_exclude_zero = 'Y' then 1 else 0 end
           and res.departdate > :p605_startdate
           and res.arrivedate <= :p605_enddate

  • View Variable for WHERE clause "ORA-06550, INTO clause expected"

    Hi Guys,
    two questions
    1. can a view have variables like:
    create view myview
    As
    myname varchar(5) = bob
    select * from mytable where name = myname
    2. if so, why does a simple select above cause
    the error "ORA-06550, INTO clause expected" ?

    Hi,
    no so direct is not possible. There are workarounds, see this thread on Asktom: [url http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1448404423206]Parameterized view
    Herald ten Dam
    http://htendam.wordpress.com

Maybe you are looking for

  • Java Add-in Installation of the Central instance installation

    I'm trying to re-install the Java Add-in Central Instance for ABAP. During the installation of Java Engine, i met the error on SecureStore step. In the LOG: >> SAP Secure Store in the File System - Copyright (c) 2003 SAP AG >> A key/value pair with t

  • Plug in directory

    Hi, I am in the process of configuration, the environment is: SQL 2005, Windows 2003, the installed component is: Weblogic 9.2, EPMA, Essbase, Planning, SmartView. when I configure the web server, I select Apachy, and the next screen ask for the web

  • Help! Exporting folders as catalogs has caused caused two usb2 hard drives to become unreadable

    Hi, I'm new to the forum and have been using LR since v5. I'm now on 5.3 this morning I exported (one at a time) several folders as catalogs from my Win 8.1 laptop hard drive to my main photo USB2 drive which is normally connected to my win 8 dektop

  • Error code 6 when re-installing CS5

    I was running a student/ teacher edition of CS5.  After a clean install of Windows 7, I cannot reactivate CS5 after copying the files back to the computer's hard drive.  I get an error code 6 when I try to launch PhotoShop.   What do I need to do to

  • Disk Utility can't find my drive. What can I do to fix it?

    I started my computer and there was a flashing folder with a question mark. I ran Disk Utility from the disk and it can't find my drive. What can I do to fix it?