TO_CHAR in where clause

Hello

Here's my query below. I added a to_char dates in my paintings (expiry_dstamp) but now my request does not take the "superior to" in my where clause into consideration.

Could someone ' a please inform me on what I should do now with my where clause.
select *
from

(select distinct sku_id pfs, location_id pfl, to_char(expiry_dstamp, 'DD-Mon-YYYY') pfexd
from inventory
where pick_face = 'F') pf,

(select distinct i.sku_id npfs, i.location_id npfl, to_char(i.expiry_dstamp, 'DD-Mon-YYYY') npfexd
from inventory i, location l
where i.pick_face is null
and lock_code is null
and i.location_id = l.location_id
and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf

where pf.pfexd > npf.npfexd
and npf.npfs = pf.pfs
order by pf.pfl
Thank you

SM

It is the taking into account, but now you're string comparison no dates...

Try this

select to_Char (pfexd, 'dd-mon-yyyy')
, to_char (npfexd, 'dd-mon-yyyy')
from

(select distinct sku_id pfs, location_id pfl, expiry_dstamp pfexd
from inventory
where pick_face = 'F') pf,

(select distinct i.sku_id npfs, i.location_id npfl, i.expiry_dstamp npfexd
from inventory i, location l
where i.pick_face is null
and lock_code is null
and i.location_id = l.location_id
and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf

where pf.pfexd > npf.npfexd
and npf.npfs = pf.pfs
order by pf.pfl

not tested

Published by: Alex Nuijten on January 7, 2010 17:45

Published by: Alex Nuijten on January 7, 2010 17:46

Tags: Database

Similar Questions

  • Convert and To_Char in where clause does not

    Hello

    I try to get the following sql beating, but it always generates an error. Any ideas?

    SELECT

    e_Equipment.EQU_ID,

    e_Equipment.EQU_PC_name,

    e_Equipment.EQU_DESCR,

    e_Equipment.EQU_SERIAL_NO,

    e_Equipment.EQU_STATUS,

    a_POBSYSENUMS. PSS_ID

    Of e_equipment

    LEFT JOIN

    A_POBSYSENUMS

    ON e_Equipment.EQU_STATUS = CONVERT (A_POBSYSENUMS. PSS_ID, ' varchar (2)') AND A_POBSYSENUMS. PSS_PSE_PK = '76'

    WHERE

    e_Equipment.EQU_ORG_PK = 8271;

    Thank you very much

    Christina

    Looks like you are trying to use the MS SQL Server syntax rather than the Oracle syntax.

    You did not say why to_char does not work for you...

    Try...

    e_Equipment.EQU_STATUS = TO_CHAR (A_POBSYSENUMS. PSS_ID)

  • 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

  • Where clause in the "default_where" of get_block_property is not cancelled...

    Hello

    I developed a form with two blocks.

    The first - block of non - database contains the criteria.

    Database of the other - block-displays the records according to the inserted.

    Also, there is a button that executes the query criteria.

    The code of the BUTTON WHEN PRESSED is as follows:

    declare

    v_where varchar2 (3000);

    Start

    v_where: = null;

    go_block ('EKKREMOTHTES_AIT_TSG');

    clear_block (no_validate);

    v_where: = get_block_property ('EKKREMOTHTES_AIT_TSG', default_where);

    If: blk_criteria.site_id is not null then

    v_where: = v_where |' and site_id = "'|: blk_criteria.site_id | ''';

    end if;

    If: blk_criteria.yphr_klimakio is not null then

    v_where: = v_where |' and yphr_klimakio = "'|: blk_criteria.yphr_klimakio | ''';

    end if;

    If: blk_criteria.send_date_from is not null and: blk_criteria.send_date_to is not null then

    v_where: = v_where |' and send_date between to_date('''|| to_char(:blk_criteria.send_date_from,'dd/mm/yyyy')||''',''dd/mm/yyyy'') and

    to_date('''|| to_char(:blk_criteria.send_date_to,'dd/mm/yyyy') | " (', "dd/mm/yyyy)";

    end if;

    If: blk_criteria.eq_group1 is not null then

    v_where: = v_where |' and eq_group1 = "' | : blk_criteria.eq_group1 | " ' ;

    end if;

    If: blk_criteria.eq_type1 is not null then

    v_where: = v_where |' and eq_type1 = "' | : blk_criteria.eq_type1 | " ' ;

    end if;

    If: blk_criteria.eq_group2 is not null then

    v_where: = v_where |' and eq_group2 = "' | : blk_criteria.eq_group2 | " ' ;

    end if;

    If: blk_criteria.eq_type2 is not null then

    v_where: = v_where |' and eq_type2 = "' | : blk_criteria.eq_type2 | " ' ;

    end if;

    blk_def_where ('EKKREMOTHTES_AIT_TSG', v_where);                                    / * a form routine that makes the set_block_property(<block>,default_where) * /.

    do_key ('execute_query');

    end;

    The above code works when the user inserts the criteria for the first time. Later when the user deletes certain criteria - clear criteria in the block of criteria-

    and he pushed the button of the query results are exactly the same...

    After have debugged the problem, clause v_where is not nullied (do not get the value zero) in order to get the new criteria.

    Can you identify the error?

    Note: I use Oracle Forms 10 g Db 11 g v.2

    Thank you very much

    SIM

    SIM,

    The procedure "blk_def_where" sets the block where clause by using the DEFAULT_WHERE or the ONETIME_WHERE constanct?  Gets it to the user that the same results as the DEFAULT_WHERE sets the property WHERE permanently so the second time through, the 'v_where' is NOT null.  Check your BLK_DEF_WHERE procedure and if it does not use the ONETIME_WHERE constanct, change isn't.  The alternative would be to put DEFAULT_WHERE = NULL after the call to the built-in EXECUTE_QUERY.

    Craig...

  • BUSINESS in WHERE Clause?

    Hi all


    I'm on oracle 10 g 2.

    I have the following where clause, whenre I need use cases for one of the filter condition in the where clause... According to one of the input parameters...
    I have the below code segment... The case statement is correct, we can use it here?

    ||
                            LEFT OUTER JOIN RNS_CORE.V_GET_DVMT VAH
                            ON DATE_RANGE.DATE_YEAR = TO_CHAR(VAH.DATA_DATE,'YYYY')
                            CROSS JOIN YEAR_SUB 
                            WHERE
                           ( CASE WHEN p_route_opposite_ind='N' THEN
                                                    ROUTE_ID = p_route_id
                                         ELSE   ( ROUTE_ID = p_route_id
                                                     OR  ROUTE_ID =(SELECT RTE_OPPOSITE_DIRECTION_RTE_ID FROM RNS_CORE.TBL_RTE WHERE RTE_ID=p_route_id))
                                          END CASE );          
                            AND  (( ROUTE_FROM_MEASURE >= P_ROUTE_FROM
                            AND   ROUTE_TO_MEASURE   <= p_route_to_measure)
                            OR (P_ROUTE_FROM BETWEEN ROUTE_FROM_MEASURE AND ROUTE_TO_MEASURE)
                            OR (p_route_to_measure BETWEEN ROUTE_FROM_MEASURE AND ROUTE_TO_MEASURE)
                            ) 
                            AND   DATA_DATE BETWEEN TO_DATE('01/01/'||TO_CHAR(TO_DATE(p_start_date,'MM/DD/YYYY'),'yyyy'),'mm/dd/yyyy')
                            AND TO_DATE('12/31/'||TO_CHAR(TO_DATE(p_end_date,'MM/DD/YYYY'),'yyyy'),'mm/dd/yyyy')
                            --AND DATE_RANGE.DATE_YEAR IS NULL
    
                        );
    Thanks in advance

    Enjoy your sugessions

    HU

    Hello

    You need not case for this. Try something like:

    WHERE   (    (       p_route_opposite_ind     = 'N'     AND route_id = p_route_id )
         OR   ( NVL ( p_route_opposite_ind
                        , 'Y'
                 )                      != 'N'     AND route_id IN (
                                                                         SELECT  rte_opposite_direction_rte_id
                                                    FROM    rns_core.tbl_rte
                                                    WHERE   rte_id  = p_route_id
                                                                      )
                 )
            )
    AND     route_from_measure     >= p_route_from
    AND     ...
    

    You can use the BOX in a WHERE clause. CASE did the same thing in a WHERE clause that he does everywhere else: it returns a single value in one of the types of SQL, such as DATE, NUMBER or VARCHAR2 data. (There is no Boolean data type in SQL).

    See this thread:
    Re: Error on the procedure

  • function defined by the user in where clause

    Hello

    Please let me know how to use user-defined in the where clause. I need to use the function that returns the date for dateid.
    It generates the error...
    SELECT To_char(fnc_get_date_for_dateid(a.postdateid),'DD-MON-YYYY') transaction_date,
           SUM(A.points) POINTS_OR_MILES_CREDITED,
           SUM(CASE WHEN a.points is null THEN a.transactionamount ELSE a.points END),              
    FROM   accrual a
    JOIN   datecal dc ON dc.dateid = a.postdateid  
    join   MemberALL m on m.memberid = a.memberid
    WHERE a.awardnumber IS NULL
      AND a.accrualtype = 'B'
    GROUP BY To_char(fnc_get_date_for_dateid(a.postdateid),'DD-MON-YYYY')
    ORDER BY a.postdateid;
    Error
    ORA-00979: not a GROUP BY expression
    00979. 00000 -  "not a GROUP BY expression"
    Thank you
    Sandy

    Hi Sandy,

    Have you tried like
    ===========================

    SELECT To_char (fnc_get_date_for_dateid (a.postdateid), 'DD-MON-YYYY') transaction_date,.
    Sum (A.points) POINTS_OR_MILES_CREDITED,
    SUM (CASE WHERE the a.points is null THEN a.transactionamount ELSE a.points END),
    The ACCRUAL one
    JOIN dc datecal ON dc.dateid = a.postdateid
    Join MemberALL m on m.memberid = a.memberid
    WHERE a.awardnumber IS NULL
    AND a.accrualtype = 'B '.
    GROUP BY a.postdateid - To_char (fnc_get_date_for_dateid (a.postdateid), 'DD-MON-YYYY')
    ORDER BY a.postdateid;
    ==========================

    Thank you
    Slokam

  • Update statement with joins of tables and where Clause

    Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.

    Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.

    The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!



    1:

    Update PenaltyAll
    Set a.indicator = month (b.)
    of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
    where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20

    2:

    Update PenaltyAll
    adjustment indicator =
    (select to_char (b., 'MM')
    of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
    "where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
    (et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
    and b.apr < 20)

    Published by: sqlrookie on August 21, 2009 07:04

    I edited my post, that was my mistake, ANC you try now?

  • Expression box in a WHERE clause

    I got a report where users spend a school id to search errors for their school. Is what I want to be able to do, if no school id is passed or they enter a 0 (zero), the report spans the entire district. This is indeed by omitting the last line in the WHERE clause:

    and (schoolid = 425 or enrollment_schoolid = 425)

    I think that a CASE expression might work but not sure how to do it.

    ****************************

    Select
    enrollment_schoolid,
    SCHOOLID,
    student_number,
    state_studentnumber,
    LastFirst,
    TO_CHAR (entrydate, 'yyyy-mm-dd'),
    Case
    When entrydate > = to_date ('01 AUG 08') and enroll_status >-1 then "Invalid Pre-Enroll status enroll_status be-1 currently ' |" TO_CHAR (enroll_status)
    When state_studentnumber is null and enroll_status >-1 then 'no. SSID must be a new student.
    When entrydate = exitdate then "No Show exit Exchange is at 01/08/2008 - Comments | TO_CHAR (transfercomment) | ' - ' || TO_CHAR (ExitComment)
    When lastfirst as '%. %' then 'period in the name '.
    When ethnicity is null then 'no ethnic group Code.
    Else "other error".
    End as error

    Of
    students

    where
    ENTRYDATE > to_date ('01 AUG 08') - do not check the previous years
    and)
    ENTRYDATE = exitdate - not the time at school
    or like '%. %' lastfirst - period in the name
    or (state_studentnumber is null and enroll_status >-1)-check the SSID
    or ethnic origin is null - no. ethnicity
    )
    and (schoolid = 425 or enrollment_schoolid = 425)

    Published by: Opus on April 30, 2009 09:46

    Hello

    Tell you if the user enters 425 as a parameter, you want the WHERE clause to include:

    and (schoolid = 425 or enrollment_schoolid = 425)
    

    But if the user enters 0 (or NULL) you want to ignore this condition?

    Assuming that the parameter is: target_schoolid, you can replace the condition above with this:

    AND (   schoolid            = :target_schoolid
        OR  enrollment_schoolid = :target_schoolid
        OR  :target_schoolid    IS NULL
        OR  :target_schoolid    = 0
        )
    

    Published by: Frank Kulash, April 30, 2009 12:54

  • where clause

    Hi Master,

    I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.

    Select * from

    ABC one

    XYZ x

    PQR p

    where a.column1 = b.column1

    and a. column 2 = value

    and b.coumn1 = c.column1

    and c. column2 = value

    and b. Column3 certain condition

    How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!

    Concerning

    AR

    Hi, Ar,

    874273 wrote:

    Hi Master,

    I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.

    Select * from

    ABC one

    XYZ x

    PQR p

    where a.column1 = b.column1

    and a. column 2 = value

    and b.coumn1 = c.column1

    and c. column2 = value

    and b. Column3 certain condition

    How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!

    Concerning

    AR

    There is no predefined order.  The optimizer uses any order that it deems will get faster results.  You can check the execution plan to see how she chose in a particular case.

    SQL is a non-procedural language.  When you write code in a procedural language, tell you How you want to do something.  When you write code in SQL, you say what you want to do.

  • Try adding conditions to clause "and" stored in the table for the where clause, unknown syntax

    I am trying to add additional segments to the 'where' clause, and I don't know exactly how to proceed. I am currently using another table to search for keywords and sometimes there aren't everything. I use this table containing the key words to search the description and associate a symbol with a path.

    The code loops through the keywords with the keywords most associated and try to find links to a symbol then excludes those and search for symbols that correspond to those with less keywords and all. I am able to do this with 6 queries and manually changing the arguments, but I want to loop together so that if the changes need to be made in the future, I won't need to go digging in the code.

    Thanks, but that's ok. I already have a solution for this.

  • Add where clause dynamically

    Hi Experts,

    I have a VO with query like select * ministries dept, emp where dept.dept_id = emp.dept_id group... by order of dept.dept_id employees

    At runtime, I need to add where clause with (and in dept.dept_id (select dept_id from table2))

    I tried to use the vo.setWhereClause () method. But it does not work

    Is there another solution?

    I use Jdeveloper 12.1.3

    Thanks in advance.

    There are various possible solutions for this. You can either use setQuery that defines the entire sql statement. However, you then need to delete where condition adding yourself too.

    Or you use viewCriteria as explained in this blog http://www.ahsanscorner.com/content/2015-11-16-1942-simulating-sql-clause-adf-viewcriteria-api.

    Another approach is described by this blog Jet binary: using bind variable for SQL statements with the paragraph who uses a SQL table to build the in clause.

    Timo

  • ViewObject where Clause SET based on logged in user roles

    Hello Experts

    I have a view object based on a custom query to get distinct values from a table. My requirement is to display the results as a listview. The listview is is filled without any problem. But I need to add a where clause clause the object view based on the user roles.

    I have a method that generates the where clause and returns one string something like "COUNTRIES ('USA', 'UK').

    I created a class of the view object Impl and put WhereClause as below: but where clause is not applied when I run the page. I see everywhere instead of just USA & UK.

    Can you let me know at what time should I set the where the clause?

    SerializableAttribute public class CountriesVOImpl extends ViewObjectImpl {}

    /**

    * This is the default constructor (do not remove).

    */

    public CountriesVOImpl () {}

    this.setWhereClause (getCountries ());

    }

    public String getCountries() {}

    return '('USA', 'UK') COUNTRIES. "

    }

    }

    In class ViewImpl try to replace "executeQueryForCollection" and setWhereClause in this function as:

        protected void executeQueryForCollection(Object object, Object[] object2, int i)
        {
            setWhereClause("COUNTRY in ('USA','UK')");
            super.executeQueryForCollection(object, object2, i);
        }
    
  • where clause to query the hierarchy in the tree Apex area does not

    Hi all

    I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.

    I'm trying to populate Tree Menu with data specific to a user successfully logged on.

    (A) table created as HR2. TREE_MENU

    menu_name varchar2 (50).

    number of menu_parent

    number of menu_child

    menu_id varchar2 (12),

    menu_path varchar2 (100),

    number of user_no

    (B) SQL statement for the tree in the Apex region

    Select case when connect_by_isleaf = 1 then 0

    When level = 1 then 1

    else                           -1

    end the status,

    level,

    'Menu_name' as the title,

    NULL as an icon,

    "MENU_CHILD" as a value.

    NULL as ToolTip,

    NULL as link

    to HR2. "" TREE_MENU ".

    -WHERE USER_NO =: P_USERNO

    Start with 'MENU_CHILD' is null

    connect prior "MENU_PARENT" = "MENU_CHILD."

    brothers and sisters of order by 'MENU_ID '.

    Note: also used static value where clause but is not workd.

    that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.

    Help, please.

    Kind regards.

    If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "MENU_NAME" as title,
           null as icon,
           "MENU_CHILD" as value,
           null as tooltip,
           null as link
    from HR2."TREE_MENU"
    start with "MENU_CHILD" is null
    connect by
        prior "MENU_PARENT" = "MENU_CHILD"
        and "USER_NO" = 7
    order siblings by "MENU_ID"
    

    Concerning

    Mahmoud

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

    )

  • Cannot run a «BUSINESS...» WHEN ' with a date in a WHERE CLAUSE condition

    Hello

    I need to check for a condition and date according to the date, he would check a set of host names or the other game... so I thought I could write something like this in the WHERE clause:

    AND HOST_NAME IN

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ON THE OTHER

    ("SERVERNAME1", "NAMESERVER2", "SERVERNAME3")

    END

    )

    I get the following:

    ORA-00907: lack of right parenthesis

    00907 00000 - "lack the right parenthesis.

    But there is no missing parentheses!

    If I take the case... when... end, and run the host_name in ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') (separately, they run fine)...

    I also tried:

    AND

    (

    CASE

    WHEN TO_DATE (: StopDate, 'MON-DD-YYYY') > = TO_DATE ('22 - DEC - 2015 "," DD-MON-YYYY ') THEN

    HOST_NAME IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC') ELSE

    HOST_NAME IN ('SERVERNAME1","NAMESERVER2","SERVERNAME3")

    END

    )

    the error I get is:

    ORA-00905: lack of keyword

    00905 00000 - 'lack the key word'

    What keyword miss me?

    Post edited by: c75d2e42-06a0-4eb1-a576-5652edcbfbe8

    Hello

    c75d2e42-06a0-4eb1-A576-5652edcbfbe8 wrote:

    It was a typo when transferred to the Oracle forum... the version of Oracle is: PL/SQL version 10.2.0.3.0 (10 G)

    I also used IF the statement and that has not worked (in error "missing parenthesis") which I'm sure is a matter of "syntax"... I did not know that the CASE statement returns the value single only, so it's probably the problem.  Is it possible to re - write this?

    ...

    IF only works in PL/SQL.  It does not in SQL, even if that SQL is embedded in PL/SQL.

    There are many ways to re - write the condition.  And here's one:

    AND ((host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    )

    OR (host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND TO_DATE (: StopDate, "MON-DD-YYYY")<  to_date="" ('dec-22-2015', ="">

    )

    )

    If: StopDate can be NULL, it must be a bit more complicated.

    You can also use nested, such as CASE expressions

    AND THE CASE

    WHEN TO_DATE (: StopDate, "MON-DD-YYYY") > = TO_DATE ('22-DEC-2015', "MON-DD-YYYY")

    WHILE CASE

    WHEN host_name IN ('SERVERNAMEA', 'SERVERNAMEB', 'SERVERNAMEC')

    AND THEN 'OK '.

    END

    OTHER CASES

    WHEN host_name IN ('servername1","Nameserver2","SERVERNAME3")

    AND THEN 'OK '.

    END

    END = 'OK '.

    I wonder if this in your application is the best way, however.  If SERVERNAMEA was put into service on December 22, maybe that that fact should be recorded in a table.  If you have a table with 1 row per server, you can consider adding 2 columns DATE to show when the server was first and last used.  Then, rather than use a WHERE clause to test servers appropriate, you could do an inner join.

Maybe you are looking for