Case instructions within a Where clause clause

Hello group,

I know this has been asked several times, but I do not enter simply to a tuition assistance box in a WHERE clause.  So I need help:

My current WHERE the clause reads:

A16. FULL_DATE between (SELECT (TRUNC (SysDate - 8)) From Dual) and (select (TRUNC (SysDate - 2)) double)

However, I need to 'automate' a bit, based on the current time/day of the month.  I need my instruction box to say:

(Case when to_char (sysdate-3, 'mm') <>to_char (sysdate, 'mm')

then the a16. FULL_DATE (between SELECT (trunc (ADD_MONTHS ((LAST_DAY(SysDate-3)),-1)+1) and (SELECT (add_months (trunc(SysDate-2)-1)) of double)))

Of another a16. FULL_DATE between (SELECT trunc (ADD_MONTHS ((LAST_DAY (SysDate)),-1)+1) From Dual) and (select (TRUNC (SysDate - 2)) From Dual)

However, I have an error on "Else".  Can someone explain what is the problem and how to fix it?  I tried both 'then' and 'Else' syntax and both will run individually.  So I'm quite sure that he does not like my CASE statement in general.

In advance, thank you for your help.

Don

I can't tell what your business logic, so here's a simple example of an instruction box in the where clause:

SQL > select *.
2 double
3 where dummy = case when extracted (sysdate months) = 9 then 'W '.
4 Once extracted (sysdate months) = 10 then 'X '.
When 5 extract (month from sysdate) = 11 then 'Y '.
6                      else 'Z'
7                 end
8;

D
-
X

Tags: Database

Similar Questions

  • several instructions box in where clause

    Hello

    I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.

    where

    i.compute_zone =

    case

    When: P14_zone is NOT NULL

    then: P14_zone

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_2 is NOT NULL

    then: P14_zone_2

    other: P14_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_3 is NOT NULL

    then: P14_zone_3

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_4 is NOT NULL

    then: P14_zone_4

    of other i.compute_zone

    end

    any suggestions?

    Thank you

    MICAH

    Hi, Micah,

    User12611868-Oracle wrote:

    Hello

    I'm trying to create report filters using substitution variables in a case statement in a where clause clause. I have several instructions box running on the same column. I don't really know how to write it. Here's what I have so far but I know I'm going in the wrong direction.

    where

    i.compute_zone =

    case

    When: P14_zone is NOT NULL

    then: P14_zone

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_2 is NOT NULL

    then: P14_zone_2

    other: P14_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_3 is NOT NULL

    then: P14_zone_3

    of other i.compute_zone

    end

    AND

    i.compute_zone =

    case

    When: P14_zone_4 is NOT NULL

    then: P14_zone_4

    of other i.compute_zone

    end

    any suggestions?

    Thank you

    MICAH

    How get the desired results of your data depends on the desired results and your data.  What do you do?  (I can't tell just by looking at the aat code that do not do).  After CREATE TABLE and INSERT statements for some sample data and a couple of sets of parameters (variables such as p14_zone) and the exact results that your choices in each set of parameters, given the same sample data.

    Check out the Forum FAQ: Re: 2. How can I ask a question on the forums?

    CASE expressions are generally not useful in a WHERE clause.  CASE expressions are a convenient way to IF-THEN-ELSE logic of the places where you can't do anything other than (the SELECT clause), but WHERE the clauses allow IF-THEN-ELSE logic in any case

    Maybe you want something like

    WHERE MERGE (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4) IS NULL

    OR IN i.compute_zone (: p14_zone,: p14_zone_2,: p14_zone_3,: p14_zone_4)

    It returns TRUE if all 4 parameters are set to NULL.  If 1 or more of them are not NULL, then it will return TRUE if i.compute_zone is equal to one of them.

  • Tuning - using the CASE statement in the WHERE clause of the query

    Hi all

    My request has been changed to use a CASE statement in the WHERE clause to examine the data to some columns based on a parameter value. This modified request is made a full table and constantly running scan. Please suggest what can be done to improve its performance:

    Query:
    SELECT LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))) AS summary_date,
    os.acctnum,
    os.avieworigin_refid,
    COUNT(1) cnt_articleview,
    SUM(NVL(autocompletedterm,0)) cnt_autocompletedterm
    FROM TABLE1 os
    WHERE os.acctnum IS NOT NULL
    AND os.avieworigin_refid IS NOT NULL
    AND os.requestdatetime IS NOT NULL
    AND UPPER(os.success_ind) = 'S'
    
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND get_date_timestamp(os.requestdatetime)  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' AND os.entry_createddate  BETWEEN 
    TO_DATE('01-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('31-MAY-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    END = 1
    AND CASE WHEN
    Param_ValueToCheck  = 'FULL' AND os.entry_CreatedDate BETWEEN 
    TO_DATE('01-APR-2011 00:00:00','DD-MON-YYYY HH24:MI:SS') AND
    TO_DATE('07-JUN-2011 00:00:00','DD-MON-YYYY HH24:MI:SS')
    THEN 1
    WHEN
    Param_ValueToCheck  = 'INCR' THEN 1
    END = 1
    GROUP BY LAST_DAY(TRUNC(TO_TIMESTAMP(os.requestdatetime, 'yyyymmddhh24:mi:ss.ff4'))), os.acctnum,os.avieworigin_refid;
    Description of the table:
    (Number of lines: approx. > amount 600 000 000)
    Name                           Null     Type       
    ------------------------------ -------- ------------
    ARTICLEID                      NOT NULL NUMBER(20) 
    USERKEY                                 NUMBER(10) 
    AVIEWORIGIN_REFID                       VARCHAR2(10)
    SUCCESS_IND                             VARCHAR2(2)
    ENTRY_CREATEDDATE                       DATE       
    CREATED_BY                              VARCHAR2(10)
    FILENUMBER                              NUMBER(10) 
    LINENUMBER                              NUMBER(10) 
    ACCTNUM                                 VARCHAR2(10)
    AUTOCOMPLETEDTERM                       NUMBER(2)  
    REQUESTDATETIME                         VARCHAR2(19)
    Explain Plan
    SQL> select * from table(dbms_xplan.display);
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Plan hash value: 2224314832
    
    ----------------------------------------------------------------------------------------------------------
    | Id  | Operation            | Name              | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    ----------------------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT     |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   1 |  HASH GROUP BY       |                   |   590 | 33040 |  2501K  (1)| 08:20:15 |       |       |
    |   2 |   PARTITION RANGE ALL|                   |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    |*  3 |    TABLE ACCESS FULL | TABLE1 |   590 | 33040 |  2501K  (1)| 08:20:15 |     1 |1048575|
    ----------------------------------------------------------------------------------------------------------
    
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    Predicate Information (identified by operation id):
    ---------------------------------------------------
    
       3 - filter(UPPER("OS"."SUCCESS_IND")='S' AND CASE  WHEN ('FULL'='FULL' AND
                  "OS"."ENTRY_CREATEDDATE">=TO_DATE(' 2011-04-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  "OS"."ENTRY_CREATEDDATE"<=TO_DATE(' 2011-06-07 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN
                  'FULL'='INCR' THEN 1 END =1 AND "OS"."REQUESTDATETIME" IS NOT NULL AND CASE  WHEN ('FULL'='FULL'
                  AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")>=TO_DATE(' 2011-05-01 00:00:00', 'syyyy-mm-dd
                  hh24:mi:ss') AND "ODS"."GET_DATE_TIMESTAMP"("REQUESTDATETIME")<=TO_DATE(' 2011-05-31 00:00:00',
                  'syyyy-mm-dd hh24:mi:ss')) THEN 1 WHEN ('FULL'='INCR' AND "OS"."ENTRY_CREATEDDATE">=TO_DATE('
                  2011-05-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "OS"."ENTRY_CREATEDDATE"<=TO_DATE('
    
    PLAN_TABLE_OUTPUT
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                  2011-05-31 00:00:00', 'syyyy-mm-dd hh24:mi:ss')) THEN 1 END =1 AND "OS"."ACCTNUM" IS NOT NULL AND
                  "OS"."AVIEWORIGIN_REFID" IS NOT NULL)
    Published by: Chaitanya on June 9, 2011 02:44

    Published by: Chaitanya on June 9, 2011 02:47

    When it is executed individually, MERGE LOGIC 1 and LOGIC of MERGE 2 take about ten for a daterange of 30 days data.

    BUT FULL is to get the scores of APR - JUN, INCR becomes partitions for MAY so not both 30 days.
    Are compare us like with like?

  • Case statement in a WHERE clause

    Gurus,

    Im trying to avoid Union of several select statements using a CASE inside a WHERE clause. When the parameter is defined as "What's new" it is advisable to use a code and for "Update Items" another condition.

    Having a problem with the following... I know that BOX in WHEREs instructions are allowed only can not make it work for this one.

    and case  when 'New Items' = 'xxx' --p_item_status 
             then  msi.creation_date = msi.last_update_date
          when 'Updated Items' = 'bbb' --p_item_status  
             then  msi.creation_date != msi.last_update_date
          else 1=1
    end;  
    Points for correct and helpful answers!

    Published by: sreese on March 27, 2012 17:51

    Hello

    The great thing about CASE expressions, is that they allow you to use a login IF-THEN-ELSE in the clause SELECT, the ORDER BY clause or anywhere else. The WHERE clause has its own way to IF-THEN-ELSE logic, so even if you can use a CASE expression in a clause WHERRE, it usually does not help anything. You can do somehting like this:

    WHERE     (     :p_item_status        = 'New Items'
         AND     msi.creation_date  = msi.last_update_date
         )
    OR     (     :p_item_status        = 'Updated Items'
         AND     msi.creation_date  != msi.last_update_date
         )
    OR     (     :p_item_status        NOT IN ( 'New Items'
                               , 'Updated Items'
                               )
         )
    

    This guess: p_item_status is not NULL.
    If: p_item_status can be NULL, and you want to include all the lines where it is, and then change the last condition to

    OR     ( NVL (:p_item_status, 'OK') NOT IN ( 'New Items'
                                 , 'Updated Items'
                                 )
         )
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions), some values of the parameter and the expected results of these data for each value of the parameter.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • Using a CASE statement in 'IN' where clause clause

    Hello

    I have a form that users see after they connect with a few items and they type or select values based on the element type. All reports in the application use these values of PAGE 1 in where clause to filter the lines.

    One of these question is "Quarter".  I have a group of radio buttons on the PAGE 1 on the P1_QTR point.

    I need to provide users a way to take the last 4, last 3, last 2 or current quarter and I need to dynamically build a clause WHERE the interactive report based on the selection in the form.

    I am trying to use the CASE as shown below and get the syntax error.

    AND QTR to (when BOX: P1_QTR = 'CURRENT' then ("T4"))

    When: P1_QTR = "LAST" then ("Q3")

    When: P1_QTR = 'LAST TWO' then ('Q3, "Q4")

    When: P1_QTR = 'LAST THREE' then ("Q2", "Q3,' T4 ')

    another ("T1", "T2", "Q3,' T4 ')

    END)

    How can I achieve this?

    Following a simple logic, try

    and QTR to

    (

    Select 'T4' double where: P1_QTR <> 'LAST '.

    Union of all the

    Select 'Q3' to double where: P1_QTR <> "in PROCESS".

    Union of all the

    Select "Q2" double where: P1_QTR not in ('CURRENT', 'LAST', "LAST TWO")

    Union of all the

    Select "Q1" double where: P1_QTR not in ('CURRENT', 'LAST', 'LAST TWO', 'THREE LATEST')

    )

  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values 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_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained 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 the following,
    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 very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth 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' values of "n".
    If overdue_flag that in ('Y', ' don't) 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'
    )
    
  • How to use the instruction box in where clause

    Hi all


    I need to use cases where clause guide me please how I can do it.


    AND WHEN BOX: KAPCO = "KAPCO" THEN cla. CLASS_NAME LIKE '% KAPCO % '.
    WHEN: KAPCO = "NON_KAPCO" THEN SUPERIOR (cla. CLASS_NAME) NOT LIKE '% KAPCO % '.
    WHEN: KAPCO = 'ALL' GOLD: KAPCO IS NULL SO SUPERIOR (cla. CLASS_NAME) LIKE '% '.
    END



    Concerning

    Published by: user10941925 on March 4, 2012 22:31

    Hello

    CASE expressions return a single value, for example a VARCHAR2. They do refer to code fragments.

    You usually don't need (or want) an expression BOX in a WHERE clause, or any other condition. I think that you were trying to do the equivalent of:

    AND     (     (:KAPCO = 'KAPCO'          AND cla.CLASS_NAME       LIKE '%KAPCO%')     -- Don't you want UPPER on this line?
         OR     (:KAPCO = 'NON_KAPCO'           AND UPPER(cla.CLASS_NAME) NOT LIKE '%KAPCO%')
         OR     (NVL (:KAPCO, 'ALL') = 'ALL'       AND cla.CLASS_NAME IS NOT NULL)
         )
    

    If you would care to post some sample data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.

  • A CASE statement with additional where clause

    Hi all

    I need assistance in which this obligation clause

    Table:-balance_table

    Columns:-balance_type, balance_amount, balance_month, budget_name

    balance_type column had given 'Real' OR 'Budget '.

    Now I am trying to extract data such as: if: entered_month is Mar-2009 then before and including Mar-2009 will show real balance sheet Date and after Mar-2009 will show budget data.

    It works fine, I need to add a condition more restrict the budget name, there are several budget_name in the table for balance_type = 'Budget '.



    SELECT SUM (balance_amount), balance_type, balance_month
    OF balance_table
    WHERE balance_type =
    (CASE
    WHEN balance_month < =: entered_month
    THEN 'real '.
    ANOTHER 'Budget '.
    END
    )
    AND budget_name = 'BUDGET1.
    Balance_type GROUP, balance_month

    Stated above is erroneous because ' AND budget_name = ' BUDGET1 "clause restricts the set of data."

    Please help in contrcuting where clause 1) to sort the data according to Budget/actual and 2) for specific budgets, so budget_type = Budget

    Thank you
    Bobin

    That should do it.

    SELECT SUM (balance_amount),
           balance_type,
           balance_month
    FROM balance_table
    WHERE (balance_type = 'Actual'
           and balance_month <= :entered_month
          )
    or (balance_type = 'Budget'
        and balance_month > :entered_month
        and budget_name = :entered_budget_name
       )
    GROUP BY balance_type,
             balance_month
    ORDER BY 2
    

    See you soon
    Sarma.

  • case of condition in where clause

    Hello

    I am a beginner in SQL, but according to my reading of the manual, this syntax should be acceptable. I'm using application express but tested also in Developer SQL and the conclusion that it fails with an error "invalid relational operator", with the line number pointing to the ELSE clause of the condition, but a number of column pointing to white space.

    This is a select statement nested, but that shouldn't matter. The fragment in question is:

    Select columns
    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 that this puts ok shaped during the validation. The code is looking for bookings within a range of dates (which works very well when the other conditions are discussed), and should only output offset lines (nights) if the user asks for it in the variable of liaison P604_EXCLUDE_ZERO. There are probably other ways to go about this, but I'm too stubborn to renounce it. Well, not yet anyway.

    Thanks and greetings
    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
    
  • case in PL/SQL where clause statement

    • Hello
    • I have a research procedure where the user can search on the city, street, zip code.
    • I need meet the 6 different combinations as I don't know what value the user will pass.
    • It should be checked if the user passes the value or not, and then look on values passed.
    • But the procedure below is out.it the slightest mistake can be transformed with if-then-else, but case statement seems much cleaner in the code.
    • procedure searchaddress (pc_town IN SEARCHADDRESS. CITY % TYPE,

    pc_street IN SEARCHADDRESS. TYPICAL STREET %,

    pc_postcode IN SEARCHADDRESS. POSTCODE % TYPE,

    pResultSet to ref_cursor) as

    Start

    Open the pResultset for

    Select searchaddress_pk from searchaddress

    where

    case

    When pc_town is null then ((street = pc_street) and (ZipCode = pc_postcode))

    When pc_street is null then ((town = pc_town) and (ZipCode = pc_postcode))

    When pc_postcode is null then ((town = pc_town) and (street = pc_street))

    When pc_town is null and pc_street is null then (postal code = pc_postcode)

    When pc_street is null and pc_postcode is null then (city = pc_town)

    When pc_town is null and pc_postcode is null then (street = pc_street)

    end

    end searchaddress;

    Thank you

    CenterB

    A basic concept that is important to understand - sliders aren't 'sets of results' (sets of data in memory). A cursor is a series of executable steps (see plans run to cursor). It's like a program. An extraction run the program and output data. In general, which is repeated until the cursor (aka program) is no longer found the corresponding lines.

    A ref cursor is a pointer or a handle for a such slider, passed to a caller, allowing the appellant to interface directly with this slider/program.

    The slider more effective to create a search would be one without superfluous code and predicates and filters. Consider the following approach - a beefier PL/SQL procedure, do not try and play little tricks with SQL predicates in an attempt to create one (and probably not optimal) SQL.

    (not tested/compiled code)

    create or replace procedure SearchAddress(
      town     IN SEARCHADDRESS.TOWN%TYPE,
      street   IN SEARCHADDRESS.STREET%TYPE,
      postcode IN SEARCHADDRESS.POSTCODE%TYPE,
      refCur out ref_cursor
    ) is
      curHandle integer;
      res integer;
      searchSQL varchar2(1000);
    begin
      -- create base query
      searchSQL := 'select searchaddress_pk from searchaddress where 1 = 1 ';
    
      -- add dynamic predicates as needed
      if town is not null then
        searchSQL := searchSQL || 'and town = :town';
      end if;
    
      if street is not null then
        searchSQL := searchSQL || ' and street = :street';
      end if;
    
      if postcode is not null then
        searchSQL := searchSQL || ' and postcode = :postcode';
      end if;
    
      -- create a DBMS_SQL cursor
      curHandle := DBMS_SQL.open_cursor;
      DBMS_SQL.parse( curHandle, searchSQL, DBMS_SQL.NATIVE );
    
       -- bind the dynamic bind variables added as predicate values
      if town is not null then
        DBMS_SQL.Bind_Variable( curHandle, 'town', town );
      end if;
    
      if street is not null then
        DBMS_SQL.Bind_Variable( curHandle, 'street', street );
      end if;
    
      if postcode is not null then
        DBMS_SQL.Bind_Variable( curHandle, 'postcode', postcode );
      end if;
    
      -- execute cursor (to create the cursor program) and pass it back as a ref cursor
      res := DBMS_SQL.Execute( curHandle );
      refCur := DBMS_SQL.To_RefCursor( curHandle );
    end;
    
  • problem with an instruction box in where clause getting ora-00905

    The query runs @ 07:00 every day and must return data for the last day, except Monday when the previous 3 days must be returned.

    Select ip.adm_date+ip.adm_time/86400 as admDateTime,

    IP.pt_code,

    ICC. Surname,

    CPI.first_given_name,

    IP.w_code,

    "as 'MR < 24."

    "as"MR 24-36"

    "as 'MR 36-48."

    "as"MR 48-60,"

    "" as "MR 60-72",.

    "as 'MR > 72."

    "as 'MR finalized."

    «like "Pharm/Tech",

    "as 'MR criteria."

    Of

    k_ipreg ip, k_cpireg ICC

    where ip.pt_code = cpi.pt_code

    and ip.disch_date is null

    and ip.adm_date between ((affaire quand (select to_char (sysdate,'d ') of double) = 1 then ip.adm_date > sysdate-3))

    of another ip.adm_date > sysdate-1

    end)) and sysdate

    and w_code not in ("ICW", "OEN", "ANTE", "BABY", "CHILD", "DELI", "ED", "MATY", "USSN")

    Try to learn to use properly the functions of Oracle:

    SELECT Ip.Adm_Date + Ip.Adm_Time / 86400 AS Admdatetime
         , Ip.Pt_Code
         , Cpi.Surname
         , Cpi.First_Given_Name
         , Ip.W_Code
         , '' AS "MR < 24"
         , '' AS "MR 24-36"
         , '' AS "MR 36-48"
         , '' AS "MR 48-60"
         , '' AS "MR 60-72"
         , '' AS "MR>72"
         , '' AS "MR Finalised"
         , '' AS "Pharm/Tech"
         , '' AS "Met MR Criteria"
      FROM K_Ipreg Ip, K_Cpireg Cpi
     WHERE Ip.Pt_Code = Cpi.Pt_Code
       AND Ip.Disch_Date IS NULL
       AND Ip.Adm_Date BETWEEN ( ( CASE
                                     WHEN TO_CHAR ( SYSDATE, 'd' ) = 1
                                     THEN SYSDATE - 3
                                     ELSE SYSDATE - 1
                                  END ) )
                           AND SYSDATE
       AND W_Code NOT IN ('ICW', 'NWB', 'ANTE', 'BABY', 'CHILD', 'DELI', 'ED', 'MATY', 'SCBU');
    
  • Case statement in a where clause clause

    Hi all
    This is a query that works perfectly except when: P_value don't have any value the two result Y and N should show as a result.
    I tried with a statement of NVL but it gives me an error. Someone can help me.

    -----------------------------------
    Select
    ID
    CASE
    WHEN (colonne_1) > (column_2)
    THEN 'Y '.
    ANOTHER "N".
    END 'Test '.
    OF tabel_1
    WHERE
    (CASE
    WHEN (colonne_1) > (column_2)
    THEN 'Y '.
    ANOTHER "N".
    END
    ) =: P_value
    ---------------------------------

    When: P_value have no any value the two result Y and N should show as a result.

    It is not fair

    SELECT id, CASE WHEN (column_1) > (column_2) THEN 'Y' ELSE 'N' END "Test"
      FROM tabel_1
     WHERE (CASE WHEN (column_1) > (column_2) THEN 'Y' ELSE 'N' END = :p_value
         OR :p_value IS NULL)
    

    ??

  • How to set a null column in a where clause clause involving a statement box

    In oracle APEX, I a (selection list) element called: P32_STATUS. It contains two values of interest (for this discussion): 'Available' and 'checked '. In my report, I have a column called vc_status that contains two values: "Checkbox" and NULL. In my application I want to use a case statement in my where clause similar to the lines of

    where

    .

    .

    .

    AND (vc_status = CASE WHEN: P32_STATUS = "Checkbox" THEN : P32_STATUS )

    WHEN : P32_STATUS = 'Available' THEN NULL END)

    The 'box' filtering works but the filtering to try to vc_status the NULL value does not work. Can someone help me? Thank you!

    (P.S. My intuition says that there because I can not put vc_status = NULL, but I must say that vc_status IS NULL... However, I don't know how to do execution IS ZERO inside a CASE statement)

    Hello

    Your intuition is right...

    In Oracle NULL is a bit special:

    NULL = NULL is false

    NULL <> NULL is false

    Thus, instead of the parameter a NULL value in the CASE WHERE there is just set a value on the other side:

    NVL (vc_statut, 'Available') =: P32_STATUS

    That's all! Simple, clean and functional

  • WHERE clause order ox performance question

    I do not understand order of execution of a WHERE clause, the use of a complex database

    I want to write a SELECT statement with the following condition

    ... WHERE (branch = 'main') AND (type = 1) OR (AND the costs-1 = 2).

    My question is

    < 1 > yoyu can use parentheses within a WHERE clause

    < 2 > how you would write such a clause as above if you cannot use parenthesis

    Thank you

    Hello

    Yes, you can have parentheses in a WHERE clause.
    I highly recommend to use when you need to use both AND and or in the same WHERE clause, since

    WHERE  (    x
            AND y
            )
    OR      z
    

    is not the same as

    WHERE   x
    AND     (   y
            OR  z
            )
    

    As others have said:

    ( charge -1 AND charge = 2 )
    

    will cause a compilation error.
    Here's the syntax valid and quite reasonable (although somewhat obscure):

    WHERE     (     branch = 'main'
         AND     type    = 1
         )
    OR          (     charge != -1
            AND     charge !=  2
         )
    
  • Case with where clause - ORA-00920: invalid relational operator

    Hi all, when I try to run the following query, I get the following error...

    ORA-00920: invalid relational operator

    00920 00000 - "invalid relational operator.

    * Cause:

    * Action:

    Error on line: column 16: 5

    Anyone know what the problem with my request? Thanks in advance.

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    CASE WHERE period

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END as number 'months '.

    ORDER OF CONCAT (year, number 'months') / / DESC

    The problem is the number 'month' - you cannot give an "ACE" alias for an expression in a where clause clause.

    You have not really given any condition, that a set of translations of period in a number.

    Also, you didn't say what you're trying to do.

    Maybe you want to:

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    WHERE something

    ORDER OF CONCAT (year, period of the CASE

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END DESC)

    /

Maybe you are looking for

  • Satellite A200-1AG - what modules of memory for the upgrade?

    Hello! I have a + * Satellite A200-1AG * +. I'm planing to upgrade the memory to 4 GB. Mine uses + (2x1GB) DDR2 - 667 Mhz + and I saw only 2 modules of 2 GB DDR2 - 667 Mhz + cost the same as + 2x2gb DDR2-800 +. I benefit in any way from this upgrade?

  • Satellite Pro U300 - it just freezes and makes a noise

    Hello! I think I have a very similar problem!Since I bought my computer happens but not on startup. When I'm with her, she just freezes, makes a loud noise and I can't do anything to turn off, I need to use the same radical technique! Hold the reset

  • Question about driver Ethernet for Satellite A100-294

    I tried both the Toshiba site LAN drivers but he dosnot work.Please, help me find a.

  • LinkBucks

    Whenever I trying to access some Web sites or toast on the links, I get a pop up on "linkbucks" screen and it won't let me get to what I'm doing. When this screen it keeps trying to download some sort of program and when I try to get out, she just ke

  • How to take advantage of deeply nested structures

    I'm relatively new to LabVIEW and I get in this situation: When tasks get complicated a bit more, my programs use many structures nested loop, case and structures of the sequence. Now, how we're out of nested structures quickly and cleanly? In a lang