several conditional parameters in where clause

How to select records in a table, when I say emp, a parameter for where the condition as
If empno is known then use in where clause,
If ename is known then use ename in where clause,
If both are known then use two parameters in where clause.

I use Oracle 9i.
psuedo code.
...
if p_empno is not null and p_ename is not null then
select * from emp 
where empno=p_emp and ename = p_ename ;
elsif p_empno is null and p_ename is not null then
select * from emp 
where ename = p_ename ;
elsif p_empno is not null p_ename is null then
select * from emp 
where empno=p_emp ;
else 
select * from emp 
end if ;
...
How can I do this in sql and plsql


Thank you

Published by: user10999538 on July 15, 2009 03:29

Solution

SELECT *
FROM   emp
WHERE  Nvl(empno,-9999) = Coalesce(p_empno,empno,-9999)
       AND Nvl(ename,'X') = Coalesce(p_ename,ename,'X')
/
 

SS

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.

  • a logical condition in a where clause clause

    Hello

    I am trying to retrieve the 'quantity' where ' serial = 1 and "the Serial expiry_date is > sysdate and the amount of it <>0"?

    I wrote a select statement, I don't know that I'm right or not, please correct me if I'm wrong by writing the terms in brackets:

    SELECT THE AMOUNT IN V_QTY

    OF ITEM_DETAIL

    WHERE SERIAL = 1

    AND (TRUNC (EXPIRY_DATE) > trunc (sysdate))

    AND AMOUNT <>0);

    is it good?

    Hello

    Hi Salem wrote:

    Hello

    I am trying to retrieve the 'quantity' where ' serial = 1 and "the expiry_date of this series is > sysdate and the amount of it <> 0"?

    I wrote a select statement, I don't know that I'm right or not, please correct me if I'm wrong by writing the terms in brackets:

    SELECT THE AMOUNT IN V_QTY

    OF ITEM_DETAIL

    WHERE SERIAL = 1

    AND (TRUNC (EXPIRY_DATE) > TRUNC (SYSDATE))

    AND QUANTITY <> 0);

    is it good?

    You don't need external all brackets, but they don't really hurt anything.  Leaving them it will not damage allows you to get the wrong results, or make the query more slowly.

    If all the conditions are joined by AND then classify parentheses doesn't change anything.  In other words, all the following conditions are equivalent:

    • x AND y AND z
    • (x AND y) AND z
    • x AND (y AND z)

    There is also no need to truncate the upper date.  It is not cause wrong results, but according to you the table, it could significantly slower query.  You do not want to call an additional function when you don't need to.  Comparison expressions are sometimes much faster if a column in your table (for example, expiry_date in this case) is the only one on one side of the comparison operator, because the optimizer can use an index in this way.

    I would like to do this way:

    SELECT quantity

    IN v_qty

    OF ITEM_DETAIL

    WHERE SERIAL = 1

    AND EXPIRY_DATE > TRUNC (SYSDATE) - NOT QUITE: see answer #3, below

    AND QUANTITY <> 0

    ;

  • Conditional function on "where clause".

    Hi guys,.

    How can I get a condition with function on "where to?"

    something like that:

    Get-VM | where{@{N="Path";E={Get-Path -Object $_}} -Like "*SAP*"}
    

    I don't want to get a container with properties of select objects, I want to take an object.

    It works when I call the function Select-object level and then check the result in "where" column

    PS. Sorry for my English I'm not native.

    You could do something like that

    Get-VM | where{(Get-Path -Object $_) -Like "*SAP*"}
    

    But it depends on what the function Get-path is in effect?

    Is it returns a [string] object? If so, the above should work.

  • Outer joins and null in the 'where' clause condition

    Hi people,

    Please help me on this.

    Here's my query.

    with x

    (select 'a' as a dual union all col1)

    Select 'b' as col1 of union double all the

    Select 'c' as double col1

    ),

    y as

    (

    Select 'b' as col2 from dual Union all the

    Select 'c' as col2 from dual Union all the

    Select would be "as col2 from dual Union all the"

    Select 'e' as col2 from dual

    )

    Select * x y right outer join

    on x.col1 = y.col2 and y.col2 is null

    Get all the lines of 'COL1' as null. Why like this?

    Just add the condition to the WHERE clause for example

    WITH x AS
    (SELECT 'a' AS col1 FROM dual UNION ALL
    SELECT 'b' AS col1 FROM dual UNION ALL
    SELECT 'c' AS col1 FROM dual
    ),
    y AS
    (
    SELECT 'b' AS col2 FROM dual UNION ALL
    SELECT 'c' AS col2 FROM dual UNION ALL
    SELECT 'd' AS col2 FROM dual UNION ALL
    SELECT 'e' AS col2 FROM dual
    )
    SELECT * FROM x LEFT OUTER JOIN y
    ON x.col1=y.col2                     ----want to add "and y.col2 is null " condition to get value "a"
    where y.col2 is null
    
  • 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

  • Max value return value despite where clause is not not really looking for the reason

    Hello

    Using oracle 11.2.0.3

    Select 'A '.

    of the double

    where 1 = 2

    No returns no row, as expected

    Select max ('A')

    of the double

    where 1 = 2 - that is to say isn't true

    Returns the line with null

    Why is this?

    Thank you

    Hello

    user5716448 wrote:

    Hello

    Thanks for the reply.

    I guess that's rule ageneral wait even if no line because of the place where the condition.

    where 1 = 2 - that is to say isn't true

    Thank you

    Yes, if there are no rows in the table, or no line meets the conditions in the WHERE clause, it would be logical that the query return lines exactly 0, but it is also logical that the query returns exactly 1 row.  People who have designed SQL apperantly thought return 1 row was most helpful.

    If you want the query to return 0 rows when there is no data, you can GROUP BY a constant.  For example:

    SELECT MAX (hiredate) AS last_hitedate

    FROM scott.emp

    WHERE deptno = & deptno_wanted

    GROUP 0

    ;

    If there are any rows that meet the condition in the WHERE clause, then the query will produce 1 row, but if no rows meet this condition, then the query will return 0 rows.

    Personally, I'm happy that they designed this way SQL.  I find it rather convenient that the aggregates without GROUP BY clause will return 1 row.  I do things like

    SELECT COUNT (*)

    FROM table_x;

    often, when I want to know if a table has been filled or not.  Seeing a 0 for the output is much clearer that does not get any results.

  • space in where clause

    Hello
    When I run this application it shows no record
    SQL> select * from mas_unit where unit_name!='';
    
    no rows selected
    
    SQL> select * from mas_unit where unit_name='';
    
    no rows selected
    But if I use a space in where clause, it shows the records
    select * from mas_unit where unit_name!=' ';
    
    13364 rows selected.
    Please can someone explain what oracle doing here?

    Thanx

    11 g DBA wrote:
    Hello
    When I run this application it shows no record

    SQL> select * from mas_unit where unit_name!='';
    
    no rows selected
    
    SQL> select * from mas_unit where unit_name='';
    
    no rows selected
    

    But if I use a space in where clause, it shows the records

    select * from mas_unit where unit_name!=' ';
    
    13364 rows selected.
    

    Please can someone explain what oracle doing here?

    Thanx

    Oracle sees the empty string ('') as NULL.
    Use IS NULL or IS NOT NULL instead of = or! =
    documentation http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements005.htm#g194888

    Nulls in Conditions
    A condition that evaluates to UNKNOWN behaves almost like FALSE. For example, a SELECT statement with a condition in the WHERE clause that evaluates to UNKNOWN returns no rows.

  • How to go from LOV where clause Page CO params

    Dear members,

    I have an OFA Page for which I have defined a CO.

    I also have a LOV for which I have two parameters in where clause.

    Now my requirement is to pass the two values in the where clause of LOV to the co of the corresponding page parameters.

    Anyone can guide me please in implementing this requirement.

    Best regards
    Arun Reddy

    Hi Arun

    as gyan, suggested trying attching a new controller of lov or extend its existing controller.

    In the CO page
    store the parameter which must be transmitted to lov in pageContext.putSessionValue (paramName, paramValue)

    In the Lov CO page, processrequest
    retrieve the stored values using pageContext.getSessionValue (paramName)

    Concerning
    Ravi

  • Details on the order of columns in a Where Clause

    Hi All
    My both Quarries  are giving same record count .
    so  can  i say that the order of the columns("msib.inventory_item_id=pol.item_id" AND" pol.item_id=msib.inventory_item_id ") 
    in the where  clause doesn't effect the query result in any situation 
    {code
    }
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pll.ship_to_organization_id = msib.organization_id ----------------1
    and msib.inventory_item_id=pol.item_id --------------------------2
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    group by 1
    
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pol.item_id = msib.inventory_item_id  ----------------------------------2 
    and pll.ship_to_organization_id = msib.organization_id -----------------------------1 
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    Thank you

    Published by: vijay539 on November 20, 2009 09:17

    Published by: vijay539 on November 20, 2009 09:18

    Published by: vijay539 on November 20, 2009 09:19

    Published by: vijay539 on November 20, 2009 09:19

    Hello

    Right; the order in which the columns appear in the SELECT clause has nothing to do with the lines that are in the result set.

    In fact, unless you say SELECT DISTINCT , I don't think there's anything (except to trigger an error) you can do in the SELECT clause, which would change the lines are selected.

    Published by: Frank Kulash, November 20, 2009 12:45

    Sorry, I misread the question. You may have about the order of the conditions in the WHERE clause, not the SELECT clause.

    The answer in short is the same:
    Right.

    Unless you mix ANDS and ORs (no one should ever do and that you are not), the order of the conditions will make no difference in the results.

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

  • May I ask where clause to satisfy two conditions at the same time (and)

    Hello

    I wrote a few joins and usually in the final stage where condition with certain conditions be satisfied in where clause. In all conditions where I only want one and condition fulfilled only if both are collected.

    If we look at the this funciton is I should meet (get_order_type (ogr.order_number) <>'R')) AND wh1.third_party_warehouse! = 'Y') but I'm not get rid off both that if order_type is 'R' they are removed and if tooling_group is yes then ther are removed the result. I'm trying with both below pointed out together how can check these conditions? I can do in where clause?

    ((sg.tooling_stock_group <> 'Y'))

    and

    (get_order_type (ogr.order_number) <>'R'))

    Of order_goods_received ogr

    LEFT JOIN part_master pm

    On ogr.part_number = pm.part_number

    -stock_groups sg left join

    SG stock_groups left join

    on pm.stock_group = sg.stock_group

    and ((sg.tooling_stock_group! = 'Y'))

    and (get_order_type (ogr.order_number)! = 'R'))

    -Pm.stock_group = sg.stock_group

    LEFT JOIN batch_record_1 br1

    -A FEW MORE CODE HERE-

    WHERE ((ogr.delivery_date > = trunc (date_départ)))

    AND

    ((ogr.delivery_date < = trunc (end_date)))

    AND

    OGR.goods_received_number <>'1' AND

    get_order_type (OGR.order_number) NOT IN ('L') AND

    OGR.returned_to_supplier_indicator not in('S','L') and

    -sg.tooling_stock_group <>'Y '.

    -((sg.tooling_stock_group <> 'Y') and (get_order_type (ogr.order_number) not in ('R')))

    -(get_order_type (OGR.order_number) <>'R' AND sg.tooling_stock_group <>'Y')

    ((sg.tooling_stock_group <> 'Y'))

    and

    (get_order_type (ogr.order_number) <>'R'))

    AND wh1.third_party_warehouse! = « Y »

    UNION

    (

    Thank you.

    Whenever you have a problem with such logic, you should try and draw a logic state diagram:

    In your case, you are looking to two variables, with two possible States (equal to a value or is not it)

    Then, take this sense of the sg.tooling_stock_group T and O as being the get_order_type (ogr.order_number) and create a state diagram logical based on your description of what you want.  We will use a value of "Y" to indicate we want to record and a value of "N" to indicate the folder should not be returned.

    Start with an empty logical diagram...

    T = 'Y' T! = « Y »
    +---------+---------+
    |         |         |
    |         |         |
    |         |         | O = 'R '.
    |         |         |
    |         |         |


    +---------+---------+
    |         |         |
    |         |         |
    |         |         | O! = « R »
    |         |         |
    |         |         |
    +---------+---------+

    First of all, you said: "If there is the result returned by the defined user function is"R"and the table that has the tooling_stock_group y then it should avoid this record."

    T = 'Y' T! = « Y »
    +---------+---------+
    |         |         |
    |         |         |
    |    N    |         | O = 'R '.
    |         |         |
    |         |         |
    +---------+---------+
    |         |         |
    |         |         |
    |         |         | O! = « R »
    |         |         |
    |         |         |
    +---------+---------+

    Then you said: "If order_type does not return" R' but the tooling_stock_group is 'Y', then I should not avoid recording ".

    T = 'Y' T! = « Y »
    +---------+---------+
    |         |         |
    |         |         |
    |    N    |         | O = 'R '.
    |         |         |
    |         |         |
    +---------+---------+
    |         |         |
    |         |         |
    |    Y    |         | O! = « R »
    |         |         |
    |         |         |
    +---------+---------+

    Now, you have not given any logic for the rest of the diagram, so I made the assumption that you do not want to avoid these records...

    T = 'Y' T! = « Y »
    +---------+---------+
    |         |         |
    |         |         |
    |    N    |    Y    | O = 'R '.
    |         |         |
    |         |         |
    +---------+---------+
    |         |         |
    |         |         |
    |    Y    |    Y    | O! = « R »
    |         |         |
    |         |         |
    +---------+---------+

    Now there are different ways to determine the location of the clause of this diagram.
    We could say that we want the records for all of the T column! = "Y" or all the records for all of the O line! " = R...

    where (sg.tooling_stock_group! = 'Y' or get_order_type (ogr.order_number)! = 'R')

    We say we want to EXCLUDE (using DO NOT) all records where T = "Y" AND O = "O" "

    If not (sg.tooling_stock_group = 'Y' and (ogr.order_number) get_order_type = 'R')

    Those are the two most logical ways to do.
    (In my previous answer, that we can see in this diagram, there is no need of the "or get_order_type (ogr.order_number).) (= 'R' "part, which is superfluous, but would not break it)

    Now let's look at your logic to see what it looks like to in the diagram...

    where ((sg.tooling_stock_group <> «Y»))
    and (get_order_type (ogr.order_number) <> 'R')
    )

    In a logic diagram that looks to...

    T = 'Y' T! = « Y »
    +---------+---------+
    |         |         |
    |         |         |
    |    N    |    N    | O = 'R '.
    |         |         |
    |         |         |
    +---------+---------+
    |         |         |
    |         |         |
    |    N    |    Y    | O! = « R »
    |         |         |
    |         |         |
    +---------+---------+

    As you can see, your logic was only targeting one of the 4 possible results for select records and excluding 3.

  • Difference-conditions (join and a Where Clause)

    Hi people,

    I need to clearly agree on what a difference exactly when we put any condition in INNER JOIN and the WHERE Clause.

    I have tried both way and found the same results. Even in the statistics Plan not much differences.  Any help would be appreciated.

    As:

    1 here, I use filter store in the join condition - Inner

    "SELECT i., Gl * Sc1.Item I.

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    And Gl.Location_Id in (1767, 1747,202,1625)

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    And I.Condition_Id! = 325

    2. here I use filter store in Where clause-

    SELECT i., Gl * Sc1.Item I

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    and I.LOCATION_ID in (1767, 1747,202,1625)

    And I.Condition_Id! = 325

    Thank you

    Mark



    Hello

    MarkCooper wrote:

    Hi guys,.

    To reply to all - I understand.

    1. its good practice to use conditions / filter (except CLAUSE) in the WHERE Clause rather Inner join? bon ?

    2. now, in my previous example. We could use the location code in where clause as it was in the two tables.

    What is the best practice to use the code to location here ( 1 /2) ?

    1. here I use filter store in the Inner join condition ( guess the location code is not in the article table)).

    "SELECT i., Gl * Sc1.Item I.

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

      And Gl.Location_Id in (1767, 1747,202,1625)

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

    And I.Condition_Id! = 325

    2. here I use filter store in Where clause (assume that the location code is not in the article table)-

    SELECT i., Gl * Sc1.Item I

    Inner Join Sc1.Part P

    On P.Part_Id = I.Part_Id

    Inner Join Sc1.Location Gl

    On Gl.Location_Id = I.Location_Id

    Inner Join Sc1.Condition C

    On C.Condtion_Id = Gl.Condition_Id

    Where I.Inactive_Ind = 0

      And Gl.Location_Id in (1767, 1747,202,1625)

    And I.Condition_Id! = 325

    Thank you

    If location_id isn't in the item table, then the join condition

    On Gl.Location_Id = I.Location_Id

    will cause an error.

    Once more, it should not affect results or performance if a condition like

    Gl.Location_Id in (1767, 1747,202,1625)

    is in the clause or the WHERE clause.  No matter if it is be a column called location_id in any other table, or if the same column Gl.Location_Id is used in other conditions.

    As this condition only refers to a table (GI), I recommend you put it in a WHERE clause, just to make the code clearer.

    Yet once, this applies only to the inner joins, not for outer joins and not to CONNECT BY queries.

  • Condition within a where condition clause

    Dear friends,
    I am a beginner in PL/SQL and I need your help.
    I'll show you my code (it does not):
    declare
        var_mese VARCHAR2 (2);
    begin
        select max(to_number(MESE)) 
        into var_mese
        from NOC_MONITORAGGIO;
           SELECT count(*)
            FROM noc_sdoc_work a,
                 noc_sdoc b,
                 NOC_MONITORAGGIO
           WHERE NVL(a.CD_STRUTTURA,'x') = NVL(b.CD_STRUTTURA,'x')
             AND NVL(a.CD_SUB_STRUTTURA,'x') = NVL(b.CD_SUB_STRUTTURA,'x')
             AND NVL(a.NR_PRATICA,'x') = NVL(b.NR_PRATICA,'x')
             AND NVL(a.ASL,'x') = NVL(b.ASL,'x')
             AND b.STATO IN ( 1, 2 )         
            and
                if  var_mese in ('03','04','05','06','07','08','09','10','11','12') then
                    NOC_MONITORAGGIO.ANNO_GESTIONE = b.ANNO;
                else
                    NOC_MONITORAGGIO.ANNO_GESTIONE = to_number(b.ANNO)-1;
                end if;
    end;
    My problem is here:
            and
                if  var_mese in ('03','04','05','06','07','08','09','10','11','12') then
                    NOC_MONITORAGGIO.ANNO_GESTIONE = b.ANNO;
                else
                    NOC_MONITORAGGIO.ANNO_GESTIONE = to_number(b.ANNO)-1;
                end if;
    I need a nested where condition

    Thank you
    Leo

    You can code box that using a statement in the WHERE clause:

     and NOC_MONITORAGGIO.ANNO_GESTIONE =
                case
                   when var_mese in ('03','04','05','06','07','08','09','10','11','12') then b.ANNO
                   else to_number(b.ANNO)-1
                end
    
  • 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.

Maybe you are looking for

  • Convert to text timevalue

    3.6.2 numbers Mac OS X 10.11.6 I need either displays a decimal number, created by the timevalue function in the format 'hh' or using a formula to create the text equivalent of the value of time. Automatic data format it just displays as a decimal nu

  • Web videos on two sites do not play

    I tried to watch videos on cbsnews.com and abcnews.com (nbcnews.com has no problem), but have had no success on each site. On cbsnews.com, I get a request to disable Ad-Block; I do, but I always get the request. On abcnews.com, the videos don't load

  • What happened to the context menu item 'Add album artwork' in iTunes 12.4?

    I love the new version 12.4 (return of the sidebar). What happened to the item of the context menu add album work? Someone tell me where to find it.

  • Apple fake invoices beware of guys and girls

    You can or don't already know, beware of the false abdesslem invoices. You can spot their fake as e-mail addresses always different and doesmt say apple as my emails done. They say that you bought something over £100 to stop had so not that you click

  • G72 will not load an OS with 8 GB RAM max

    This is a head scratcher. I have a G72 with 2x2gb DDR3 1333 and I wanted to move to 8 GB. I bought 2 x 4 GB 1600. When I installed it, the computer should restart. BIOS would see all the RAM, but when Windows tried to launch I get the following error