Multiple WHERE query

Is it possible to use WHERE more than once in a query?
eg.
stmt.executeUpdate("UPDATE Audit " + "SET Log_Off_Time = '" + hourValue + ":" + minuteValue + "' WHERE Username = '" + getUserName() + "' & WHERE Log_Off_Time = 0");

Also, as was implied but never stated in the post above, you do not need to repeat your WHERE, just simply string the ANDs together...
SELECT * FROM <table> WHERE <fieldA> = 'foo' AND <fieldB> = 'bar' AND ...

Similar Messages

  • "Invalid Column" on multiple where clauses with subqueries and cfqueryparam

    I'm seeing a behavior in the coldfusion cfquery that I'd like to find an exmplanation for .  I've got a query that does a subquery in the select portion and if I have multiple where lines, I get an "invalid column name" message for my second where clause, but only when I'm using cfqueryparam
    For example on the following I get "Invalid column name 'position_id'"
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND     position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND     staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">
    If I change the order of my where clause so staff_id is first, then it tells me "department_id" is an invalid column.
    If I only have one where clause, it works.  (i.e. WHERE position_id = <cfqueryparam value="#arguments.posid#" cfsqltype="cf_sql_integer">).
    If I remove the where clause from my subquery (WHERE     item_id = department_staff_tbl.staff_id) it works.
    It also works if I remove the cfqueryparam from my where clause so that my query looks like this:
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_id = #arguments.deptid#
    AND     position_id   = #arguments.posid#
    AND     staff_id      = #arguments.staffid#
    Any thoughts?

    I see two tables. So can the server. So, use qualified column-names.
    SELECT   department_staff_tbl.*,
             (   SELECT   max(bookmarked_items_tbl.bookmark_id)
                 FROM     bookmarked_items_tbl
                 WHERE    bookmarked_items_tbl.item_id = department_staff_tbl.staff_id
             ) AS bookmark_id
    FROM     department_staff_tbl
    WHERE    department_staff_tbl.department_id = <cfqueryparam value="#arguments.deptid#"  cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.position_id   = <cfqueryparam value="#arguments.posid#"   cfsqltype="cf_sql_integer">
    AND      department_staff_tbl.staff_id      = <cfqueryparam value="#arguments.staffid#" cfsqltype="cf_sql_integer">

  • How to combine insert and where query ?

    hi..
    could somebody guide me how to combine insert and where query ?
    insert into tdc_imarspc (ANUMBER,EMF_ID,PRODUCT) values ('1234567','65','ITFS')
    where anumber not like '1234567';
    Thank you,
    Baharin

    Hi, Baharin,
    As Mahesh said, WHERE only works on a query.
    You can always base a query on dual, like this:
    INSERT INTO
    tdc_imarspc (ANUMBER,     EMF_ID,     PRODUCT)
    SELECT          '1234567',     '65',     'ITFS'
    FROM         dual
    WHERE          anumber      NOT LIKE '1234567';Of course, you can use a literal, like '1234567' in both places where I used the bind variable, but if you're not using a variable, why would you want to?
    You could also put all the literals in a sub-query (based on dual), and reference column names in the main WHERE clause, LIKE THIS:
    INSERT INTO
    tdc_imarspc (     ANUMBER,     EMF_ID,          PRODUCT)
    WITH     sub_q
    AS  (
        SELECT    '1234567' AS an,     '65' AS ei,     'ITFS' AS pr
        FROM      dual
    SELECT          an,          ei,          pr
    FROM     sub_q
    WHERE      an      NOT LIKE '1234567'; 
    I assume you're not really saying
    an      NOT LIKE '1234567'If you're not using any wild cards after LIKE, you might as well use !=
    an      != '1234567'

  • Join and Multiple where clauses: which is better??

    There was an argument between a colleague and I. He prefers building his views joining many tables with many where clause while I am cute with my join which is simpler and more understandable for me. So, it started an argument on which is a superior way of joining tables.
    I will actually like to know we is faster and better: using JOINs or using multiple where clauses to retrieve values from multiple tables.?

    Dave:
    "Are we talking about the difference between Oracle Joins and ANSI Joins?
    e.g.
    Select d.dept_name, e.emp_name
    from dept d, emp e
    where d.dept_id = e.dept_id"
    That is not really an "Oracle Join". That syntax works on just about every SQL database I have ever worked with. The (+) syntax for an outer join is Oracle specific, but some other databases use a similar style for outer joins (something like a.c += b.c or a.c *= b.c).
    OP:
    There are things you can do with the ANSI style syntax that either cannot be done, or cannot be done as easily, with Oracle's syntax. Most notably, outer joining one table to more than one other tables, and FULL OUTER joins.
    Having said that, in my experience, both are rather rare occurrences, so I tend to stick to doing the jopins in the WHERE clause because that is what I am used to.
    John

  • Help with query - multiple where in grouped column

    4 columns in table named RRID1
    RRI_ID
    USER_ID
    PROCESS_TYPE
    FUNCTION
    not sure how to make this query.
    Need to pull all RRI_ID's where PROCESSTYPE ='INFO' and PROCESSTYPE ='RESOLUTION'
    for that RRI_ID.
    so same user, same RRI_ID and 2 process records, 1 INFO and 1 RESOLUTION
    so not if there is duplicate info, just if there is info and resolution.
    This is what some of data looks like..
    PROCESSTYPE|USER_ID|FUNCTION|RRI_ID
    INFO 3668 30287 817
    INFO 3748 30287 817
    INFO 4714 30287 817
    INFO 4875 30287 817
    INFO 4882 30287 817
    INFO 4885 30287 817
    INFO 3748 30288 818
    INFO 4714 30288 818
    INFO 4716 30288 818
    INFO 4882 30288 818
    INFO 4885 30288 818
    INFO 3668 30289 819
    INFO 4716 30289 819
    INFO 4875 30289 819
    INFO 4882 30289 819
    INFO 4885 30289 819
    INFO 3668 30290 820
    INFO 4716 30290 820
    INFO 4875 30290 820
    INFO 4882 30290 820
    INFO 4885 30290 820
    INFO 3668 30291 821
    INFO 4714 30291 821
    INFO 4716 30291 821
    INFO 4875 30291 821
    INFO 4882 30291 821

    you will have a stroke before you hit 40That's not the point, but thanks for your concern and you'll probably end up having a stroke sooner than me if you keep asking questions this way ;)
    Point is: stick to your original thread/question, keep it all together, be complete, instead of reposting and starting all over again.
    It's confusing when you start a new thread, while the context of your old thread matters.
    While Blu seemed to be correct, you changed the question in your previous thread after his answer and started a new one, with the same 'data'.
    Hence me being a 'nit-picker', because by starting multiple threads:
    - you'll get the right answer slower, maybe much slower
    - we're assuming things that might be out of context, given your previous thread
    etc.

  • Is Query of Queries faster than multiple WHERE criteria?

    If I need a recordset based on two table column fields (let's say firstName and lastName), is it better to run one query with a WHERE firstName = x AND lastName = y, or is it better to query of queries and find all records with a specified firstName, and then query that query to filter only records with a specified last name?  Which is the better/faster method?
    <cfquery name="somequery" datasource="someds">
    SELECT *
    FROM sometable
    WHERE firstName = 'John' AND lastName = 'Smith'
    </cfquery>
    or....
    <cfquery name="somequery" datasource="someds">
    SELECT *
    FROM sometable
    WHERE firstName = 'John'
    </cfquery>
    <cfquery name="somequery2" dbtype="query">
    SELECT *
    FROM somequery
    WHERE lastName = 'Smith'
    </cfquery>

    As a rule of thumb, make the database server do all the work... i.e. locally.  If what you are interested is "first name = x and last name = y," then those are the only records that you want to be "sent over the little wire" to you.  "The little wire" is always the bottleneck.

  • Query with multiple where

    Hello,
    I am trying to get query using LINQ to DocumentDB and have some issues.
    This code works fine (example from https://code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af/sourcecode?fileId=132409&pathId=296733303
    var ee = client.CreateDocumentQuery<dynamic>(
    colSelfLink,
    "SELECT f.id, c.FirstName AS child, p.GivenName AS pet " +
    "FROM Families f " +
    "JOIN c IN f.Children " +
    "JOIN p IN c.Pets " +
    "WHERE p.GivenName = 'Fluffy'");
    And converted version also OK
    var ff = client.CreateDocumentQuery<Family>(colSelfLink)
    .SelectMany(family => family.Children
    .SelectMany(children => children.Pets
    .Where(pets => pets.GivenName == "Fluffy")
    .Select(pets => new
    family = family.Id,
    child = children.FirstName,
    pet = pets.GivenName
    But what if I want to add some condition on the "Family"
    var ee = client.CreateDocumentQuery<dynamic>(
    colSelfLink,
    "SELECT f.id, c.FirstName AS child, p.GivenName AS pet " +
    "FROM Families f " +
    "JOIN c IN f.Children " +
    "JOIN p IN c.Pets " +
    "WHERE f.LastName = "123" AND p.GivenName = 'Fluffy'");
    How to write it in LINQ?

    try this -
    var ff = client.CreateDocumentQuery<Family>(colSelfLink)
    .SelectMany(family => family.Children
    .SelectMany(children => children.Pets
    .Where(pets => pets.GivenName
    == "Fluffy" && family.LastName == "Andersen")
    .Select(pets =>
    new
                                family
    = family.Id,
                                child
    = children.FirstName,
                                pet
    = pets.GivenName

  • Help me with returing multiple rows - Query

    I am trying to return multiple rows and i need help with my query.
    and most important of all one of the requirement is the following:
    SERVICE LEVEL has categories Sergeant, Bonus I, All Deputies, Deputy Bailiff, Deputy Lockup, Deputy Bailiff Security, Custody Assistant,
    Security Officer, Security Assistant, Security Officer and Security Assistant, Private Security, ALL, All Sworn)
    Note: Service Level “All Deputies” includes Deputy Bailiff, Deputy Bailiff Security and Deputy Lockup
    *“All Sworn”: includes Sergeant, Bonus I, All Deputies, Deputy Bailiff, Deputy Lockup, Deputy Bailiff Security*
    //this code doesn't work cuz  case- when statement return only one row. but it works for singles such as 'Sergeant'
    select *
    from in_service
    where rank IN (CASE TRIM(UPPER(:SL))
                    WHEN 'ALL DEPUTIES' THEN
                      (SELECT DISTINCT RANK FROM IN_SERVICE
                       WHERE UPPER(RANK) LIKE 'DEPUTY%')
                    WHEN 'ALL SWORN' THEN
                   (SELECT DISTINCT RANK FROM IN_SERVICE
                   WHERE UPPER(RANK) LIKE 'DEPUTY%' OR
                   UPPER(RANK) = 'SERGEANT' OR
                   UPPER(RANK) = 'BONUS 1')
                    WHEN 'ALL' THEN
                   (SELECT DISTINCT RANK FROM IN_SERVICE
                   WHERE UPPER(RANK) LIKE 'DEPUTY%' OR
                   UPPER(RANK) = 'SERGEANT' OR
                    UPPER(RANK) = 'BONUS 1' OR
                   UPPER(RANK) LIKE 'SECURITY%' OR
                   UPPER(RANK) = 'CUSTODY ASSISTANT' OR
                    UPPER(RANK) = 'PRIVATE SECURITY') 
                    end )   I was able to get multiple rows for 'ALL' and specified category like 'Sergeant' or 'Bonus I' from the code below, but NOT for 'All Deputies' for example which includes Deputy Bailiff, Deputy Bailiff Security and Deputy Lockup. I know CASE, WHEN does NOT return multiple rows, but i am having problems writing the query to make it work for all categories as the requirements mentioned above.
    WHERE RANK IN (SELECT RANK FROM (SELECT RANK, 'ALL' ALL_SERVICE
                                            FROM IN_SERVICE
                                            UNION ALL
                                            SELECT RANK, RANK
                                            FROM IN_SERVICE) WHERE ALL_SERVICE = :SL)Please help.
    Thanks in advance

    If you define your service_level as a table then it will be much easier.
    with service_level
    as
    select 'ALL' parent_lvl, 'Sergeant' srv_lvl from dual union all
    select 'ALL', 'Bonus I' from dual union all
    select 'ALL', 'Deputy Bailiff' from dual union all
    select 'ALL', 'Deputy Lockup' from dual union all
    select 'ALL', 'Deputy Bailiff Security' from dual union all
    select 'ALL', 'Custody Assistant' from dual union all
    select 'ALL', 'Security Officer' from dual union all
    select 'ALL', 'Security Assistant' from dual union all
    select 'ALL', 'Security Officer and Security Assistant' from dual union all
    select 'ALL', 'Private Security' from dual union all
    select 'All Deputies', 'Deputy Bailiff' srv_lvl from dual union all
    select 'All Deputies', 'Deputy Bailiff Security' from dual union all
    select 'All Deputies', 'Deputy Lockup' from dual union all
    select 'All Sworn', 'Sergeant' srv_lvl from dual union all
    select 'All Sworn','Bonus I' from dual union all
    select 'All Sworn','All Deputies' from dual union all
    select 'All Sworn','Deputy Bailiff' from dual union all
    select 'All Sworn','Deputy Lockup' from dual union all
    select 'All Sworn','Deputy Bailiff Security' from dual
    select *
      from in_service
    where rank IN (
              select srv_lvl
                from service_level
               where upper(parent_lvl) = upper(:SL)
                  or upper(srv_lvl) = upper(:SL)
                   )

  • Multiple Table Query

    Hey All!
    It's been a while since I last posted a message in these
    forums. But it looks like I need your help again.
    So here is the problem:
    I have to create a list of the companies' projects, yet to
    compile the complete list I have to query 4 tables, with a one to
    many and many to many relation ship.
    Here is what I have so far.
    the main table is the projects table, hence I start with
    that. Right now I can query the table, plus the companies table
    that each project is linked to. Also, each project may have a link
    to multiple companies, so I normalized the data by creating a
    companies link table:
    SELECT projects.project_id, project.project_name,
    compproj_link.company_id
    /* I only get the company id and convert it to an actual
    name when I output */
    FROM projects LEFT JOIN compproj_link ON
    compproj_link.project_id = projects.project_id
    /* here I also filter to get only active projects */
    WHERE project.status in(1,2)
    /* I group by the project id since there might be several
    companies linked to a specific project */
    GROUP BY projects.project_id, project.project_name,
    compproj_link.company_id
    ORDER BY project_name
    This works perfectly fine when I output with the group
    attribute, but now I have to link another table... called the
    airdates. The reason is that I want to order my list by the
    contents of this table (which may or may not be present)...
    this airdates that is linked to my projects is structured
    like so:
    airdates
    airdates_id - auto num
    project_id - the project it is linked to hence could be
    linked to many projects
    then there are the actual air dates
    airdateslist
    airdateslist_id auto num
    airdates_id - since for each air date record could be
    multiple dates
    airdate_date - date field
    airdate_backupdate - another date field
    airdate_current - this is a yes/no, and specifies whether
    this date is most current.
    Hence, by doing two more LEFT OUTER JOINS in my main query
    would work fine, BUT I need to get the most current date from the
    airdateslist that is set for a particular project. and when I do
    this I get no records because as of yet, no project has an airdate
    that is current.
    So my question is if I can somehow add those airdates tables
    to my main query, and be able to sort by the current date, IF it is
    present, and if not, still have all my projects displayed?
    PS. I think I have confused myself even more when writing
    this out, so if you have any questions please write. Thank you in
    advance!
    Vega...

    First, this:
    * I group by the project id since there might be several
    companies linked to a specific project */
    GROUP BY projects.project_id, project.project_name,
    compproj_link.company_id
    doesn't accomplish anything.
    Second, when I read what you posted about the two airdates
    tables, I'm not convinced that the table structure achieves what
    the comments and fieldnames describe as the objective.
    You say none of your projects have a current airdate. Do
    these tables have any data at all? If not, it's going to be hard to
    write a query when you can't ensure you got the correct
    results.

  • Multiple where conditions in one parameter

    Hi,
    Is it possible to have more than one where condition in one parameter?
    For example, my WHERE_CLAUSE parameter holds the value "where id='12345' and name='john smith'"
    when i run the report, I get a [052008_033528064][][EXCEPTION] java.lang.NullPointerException at oracle.apps.xdo.dataengine.DataTemplateParser.getObjectVlaue(Unknown
    Source) Thus the sql statement did not execute.
    But if I change the WHERE_CLAUSE to "where id='12345'" or "where name='john smith'" it works fine.
    My observation is that if there are two where conditions, BI publisher wont allow it. Am I correct?
    But the report has to be open to the possibility of having more than one where clause condition. Is there a work around for this?
    Thanks,
    Shanak

    nope your mistaken. bip will handle multiple joins.
    1. make sure the where_clause parameter is defined in your package.
    2. make sure use & syntax
    3. make sure your sql is not malformed. This is probably the issue.
    4. also, read my article on bind variables. the practice of coding the actual value in a where clause should be avoided at all costs. Causes the query execution plan to be reparsed each time that particular query is executed.
    http://bipublisher.blogspot.com/2007/10/bi-publisher-what-lexical-understanding.html
    Ike Wiggins
    http://bipublisher.blogspot.com/

  • Multiple count query

    I'm trying to write a function to compare two different counts.
    I have patient on multiple drugs...some drugs are allergy drugs and at least one allergy drug must be marked as primary.
    select count(drug_role) as vAllergyCount, count(primary_flag) as PF, ap.patient_id
    from ae_all_drugs aed, ae_patient ap
    where drug_role = 'Allergy'
    and aed.patient_id = ap.patient_id
    and ap.patient_id like '2012%'
    group by ap.patient_id,primary_flag
    order by ap.patient_id
    when grouped by patient id and primary flag I would receive a record like this:
    VAlllergyCount | PF | patient_id
    1 | 0 | 2012AB1
    3 | 1 | 2012AB1
    If i only group by patient_id I get this (which is what I want):
    VAlllergyCount | PF| patient_id
    4 | 1 | 2012AB1
    But if I try to compare the two:
    IF vAllergyCount > 1 and PF = 1 THEN 'SUCCESS' ELSIF 'FAIL'
    I receive the error message "exact fetch returns more than requested number of rows" becuase the results are really my first query.
    Can anyone help me re-write my query to compare the values?
    P.S. I'm very new to this and this forum and I apologize for not inserting code tags. I don't know how.

    Hi,
    979105 wrote:
    Thank you for your hlep.
    I need to write a function because the SQL query is going to be used as an edit check for another program. So yes, it will have to worth my time.
    You are correct. I have a patient on multiple drugs. I want to know if there is at least one allergy drug (drug_role) > 1 if there is at least ONE primary allergy drug.
    I did initially write my function with the patient_id as an input value. Why would I not need the vAllergyCount or the pf if that is an argument?If all you want to know is 'SUCCESS' or 'FAIL', then write a query that produces 'SUCCESS' or 'FAIL'. Inside the query, it may be handy to have something like vAllergyCount or pf, but that doesn't mean that they will be returned by the query, or that you need PL/SQL variables for them.
    Here's my original function:That's a PROCEDURE, not a function. Sometimes, people use the word "procedure" lossely, to mean any kind of stored code, including functions, but never the other way around.
    \Don't forget to put another \ tag at the end of the formatted section.
    \ tags are supposed to occur in pairs. If you have an odd number of \ tags, the last one has no effect, and is displayed as regular text.
    PROCEDURE COUNT_ALLERGY_MED (
         ivPatient_ID IN VARCHAR2,
         ovErrorText          OUT     VARCHAR2 )
    IS
         vCase_ID          VARCHAR2 (25);
         vSusCount           NUMBER (3);
         vSuspectMed          VARCHAR2 (1);
         --vPrimaryFlag     VARCHAR2(1);
    cursor c1 is
         select count(*) as vSusCount
         from ae_suspect_drugs aed
         where drug_role = 'S'
         and aed.case_id = ivCase_ID
         --group by ivcase_id;
    BEGIN
    open c1;
    fetch c1 into vSusCount;
    close c1;
    IF vSusCount < 1 /*AND vPrimaryFlag IS NULL*/ THEN
         ovErrorText := 'Suspect Drug Count is less than 1' || 'SusCount: ' || vSusCount;
         ELSIF vSusCount = 1 /*AND vPrimaryFlag IS NULL*/ THEN
         ovErrorText := 'Suspect Drug count is equal to 1' || 'SusCount: ' || vSusCount;
         ELSIF vSusCount > 1 /*AND vPrimaryFlag IS NULL*/ THEN
         ovErrorText := 'Suspect Drug count is greater than 1 ' || 'SusCount: ' || vSusCount;
         ELSE
         ovErrorText := 'All criteria met';
    END IF;
    END COUNT_SUSPECT_MED;It seems like it would be more convenient to have a FUNCTION, rather than a PROCEDURE; that way you could call the function directly in a SQL statement (e.g., in the WHERE clause of a query or DML statement) as well as in PL/SQL.
    The procedure you posted seems to be quite a bit differetn from the problem you asked eariler.
    Here's one way you might write a fucntion for the earlier problem:CREATE OR REPLACE FUNCTION count_allergy_med
    ( ivPatient_ID IN VARCHAR2
    RETURN VARCHAR2
    IS
    return_str VARCHAR2 (50);          -- To be returned
    BEGIN
    SELECT CASE
         WHEN COUNT (drug_role) > 1
              AND COUNT (primary_flag) = 1
              THEN 'SUCCESS'
              ELSE 'FAIL'
         END     
    INTO return_str
    FROM ae_all_drugs     aed
    ,      ae_patient           ap
    WHERE drug_role          = 'Allergy'
    AND     aed.patient_id      = ap.patient_id
    AND     ap.patient_id     = ivPatient_ID;
    RETURN return_str;
    END count_allergy_med;
    Notice that there are no columns in the result set, nor variables in the function, that correspond to vAllergyCount or pf.
    The function above returns 1 of 2 possible values.  You couold just as well write a function that had 4 possible outcomes, or 4 basic results, each containing a variable number, such asSuspect Drug Count is less than 1. SusCount: 0
    I'm not sure why you would want such as result, since 0 is the only possible count that is less than 1, but it's easy enough to produce results like that if you really want them.
    Once again, if you'd like help, post a clear example of what you want.  Include CREATE TABLE and INSERT statements for some sample data.  Post some code where you might use the function that you're thinking of.  Give a couple of different arguments for that functuion, and the results you would want for each argument given the same sample data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Multiple where lexcial parameters (how can i handle this situation?)

    hi, I am new to reports can someone help me to solve my problem how can i use multiple lexical parameters for WHERE clause, i am using sample OE (Order Entry) schema
    User Parameters
    EID_FROM
    EID_TO
    EID_WHERE_CLAUSE
    SAL_FROM
    SAL_TO
    SAL_WHERE_CLAUSE
    QUERY
    select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,HIRE_DATE,SALARY,MANAGER_ID,DEPARTMENT_ID
    from employees
    &EID_WHERE_CLAUSE &Sal_where_clause
    AFTER PARAMETER FROM
    function AfterPForm return boolean is
    begin
    if :EID_FROM is NULL or :EID_TO is NULL
         then :EID_WHERE_CLAUSE := 'WHERE 1=1';
    ELSE
         :EID_WHERE_CLAUSE := 'WHERE EMPLOYEE_ID BETWEEN '||:EID_FROM||' AND '||:EID_TO;
    END IF;     
    if :SAL_FROM is Null or :sal_to is Null
         then :SAL_WHERE_CLAUSE := 'WHERE 1=1';
    ELSE
         :SAL_WHERE_CLAUSE :='AND SALARY BETWEEN '||:SAL_FROM||' AND '||:SAL_TO;
         END IF;
    return (TRUE);
    end;

    Thank you sir, it really helped me to solve my problem, now it looks like this and working fine, i hope now there is no logical error in my code, please suggest.
    i am really surprised by such a rapid response, i hope i will learn soon from GURUZz
    PARAMETERS_
    EID_FROM
    EID_TO
    H_DATE_FROM
    H_DATE_TO
    SAL_FROM
    SAL_TO
    L_CLAUSE
    QUERY_
    select e.employee_id, e.first_name, e.hire_date, j.job_title, d.department_name, e.salary
    from employees e, jobs j, departments d
    where e.job_id = j.job_id
    and e.department_id = d.department_id
    &L_CLAUSE
    order by e.employee_id
    AFTERPARAMETERFORM_
    function AfterPForm return boolean is
    begin
    IF :EID_FROM is NULL or :EID_TO is NULL
         THEN NULL;
    ELSE
         :L_CLAUSE := 'AND EMPLOYEE_ID BETWEEN :EID_FROM AND :EID_TO';
    END IF;
    IF :SAL_FROM is NULL OR :SAL_TO IS NULL
         THEN NULL;
    ELSE
         :L_CLAUSE := :L_CLAUSE||' AND SALARY BETWEEN :SAL_FROM AND :SAL_TO';
    END IF;
    IF :H_DATE_FROM is NULL OR :H_DATE_TO IS NULL
         THEN NULL;
    ELSE
    :L_CLAUSE := :L_CLAUSE||' AND HIRE_DATE BETWEEN ' || '''' || :H_DATE_FROM || '''' || ' and ' ||'''' || :H_DATE_TO || '''';
    END IF;
    return (TRUE);
    end;
    Edited by: M. Khurram Khurshid on Jan 4, 2012 8:44 PM

  • Please help with multiple insert query into nested table!!!!

    I am having a problem with inserting multiple references to objects into a nested table using the following query:
    INSERT INTO TABLE(SELECT Taken_by FROM courses WHERE course_number= 001)
    (SELECT REF(p) FROM persons p
    WHERE p.enroled_in = 'Computing for Business'
    The database says that p.enroled_in is an invalid identifier. I know why this is. This is because the field enroled_in is part of a subtype of person called student_type and the query above is not accounting for this properly. I would like to know the correct syntax to use so I can insert into the nested table wherever a student is enroled into the 'computing for business' course. My full schema is below:
    CREATE TYPE person_type;
    CREATE TYPE student_type;
    CREATE TYPE staff_type;
    CREATE TYPE course_type;
    CREATE TYPE module_type;
    CREATE TYPE address_type AS OBJECT
    Street VARCHAR2 (30),
    Town     VARCHAR2 (30),
    County VARCHAR2 (30),
    Postcode VARCHAR2 (9)
    CREATE TYPE person_type AS OBJECT
    Name VARCHAR2 (50),
    Address address_type,
    DOB     DATE
    ) NOT FINAL;
    CREATE TYPE staff_type UNDER person_type
    Staff_number NUMBER (2,0)
    ) FINAL;
    CREATE TYPE student_type UNDER person_type (
    Student_number NUMBER (2,0),
    Enroled_in VARCHAR2(50),
    MEMBER FUNCTION getAge RETURN NUMBER
    )NOT FINAL;
    CREATE OR REPLACE TYPE BODY student_type AS
    MEMBER FUNCTION getAge RETURN NUMBER AS
    BEGIN
    RETURN Trunc(Months_Between(Sysdate, DOB)/12);
    END getAge;
    END;
    CREATE TYPE module_type AS OBJECT
    Module_number VARCHAR2(6),
    Module_name VARCHAR2(50),
    Credit NUMBER(2,0),
    Taught_in VARCHAR2(50)
    CREATE TYPE students_tab AS TABLE OF REF person_type;
    CREATE TYPE modules_tab AS TABLE OF REF module_type;
    CREATE TYPE course_type AS OBJECT
    Course_number NUMBER (2,0),
    Course_name VARCHAR2(50),
    Dept_name VARCHAR2(50),
    Taken_by Students_tab,
    Contains Modules_tab
    CREATE TABLE modules OF module_type(
    constraint pk_modules primary key (Module_number)
    CREATE TABLE courses OF course_type(
    constraint pk_courses primary key (Course_number)
    NESTED TABLE Taken_by STORE AS students_nt,
    NESTED TABLE Contains STORE AS modules_nt;

    By the way I am using oracle 9i and trying to insert into the nested table data from a subtype (i.e student is a subtype of person)

  • Multiple Rows Query

    Hi
    Table A have 2 Columns Col1, Col2.
    I want to select all distinct values of Col1 that have 2 corresponding value ‘X’ and ‘Y’ in Col2
    create table TabA
    Col1 varchar(10),
    col2 char(1)
    insert into TabA values ('tem1','X');
    insert into TabA values ('tem1','Y');
    insert into TabA values ('tem1','Z');
    insert into TabA values ('tem2','X');
    insert into TabA values ('tem2','Y');
    insert into TabA values ('tem2','Z');
    insert into TabA values ('tem3','X');
    insert into TabA values ('tem3','Z');
    insert into TabA values ('tem4','Y');
    insert into TabA values ('tem4','Z');
    insert into TabA values ('tem5','X');I need a query that only return tem1 & tem2 as they have both X, Y in col2.
    Wishes

    Check this.
    select distinct col1 from (
    select A.*, count(case when Col2 in ('X','Y') then 1
    end) over ( partition by col1) cnt
    from TabA A)
    Where cnt = 2
    Regards
    RKWill not work for all cases:
    SQL> select * from taba;
    COL1       C
    tem1       X
    tem1       X
    SQL> select distinct col1 from (
      2  select A.*, count(case when Col2 in ('X','Y') then 1 end) over ( partition by col1) cnt
      3  from TabA A)
      4  Where cnt = 2
      5  /
    COL1
    tem1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Can I retrieve data from a multiple select query?

    I recently have been able to consolidate many queries into one large one, or into large compound queries. I found an instance where I am using a select query in a for loop that may execute up to 400 times. I tried building a huge compound query, and using DB Tools Execute Query vi, followed by the DB Tools Fetch Recordset Data vi. The query executes at the database without an error, but the Fetch Recordset Data vi only returns the first instance. Is there a way to retrieve all the data without having to send up to 400 separate select queries?

    Sorry I didn't replt earlier, I was on vacation. The query I am using is to check serial numbers, and determine if they are all valid. The programs purpose is to define a serial number to a pre-existing part number. Our company makes inclinometers and accelerometers, and this entire series of LabVIEW programs is designed to automate the calibration and testing of these units. The part number definitions can contain 3 or 4 hundred parameters, so the database itself consistes of 44 tables with potentially several hundred columns per table. It is designed to not only provide definitions to every part number, but also to store all potential raw unit data to be calculated and formed into a report at any time. The logistics of getting that much data in and out of the database have forced me to do things more effeciently. The actual query in question is to take each serial number either manually entered, or automatically picked, and see if they already exist with the part number they are being defined as. If there are any duplicates, then the program will alert the operator that serial numbers x, y, and z for instance have already been asigned as the part number in question. Currently I run a simple query once for each serial number. This works, but there may be 200 serial numbers assigned. Also the serial numbers can contain upper or lower case letters. By making all the serial number letters into capitals, then into lower case, it could mean up to 400 individual queries going out over the LAN. This is a bandwidth hog, and time consuming. I started experimenting with compound queries. The actual query used is below.
    SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000005';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000006';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000007';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000008';SELECT SERIALNO FROM "maintable" WHERE PARTNO = '475196-001' AND SERIALNO = '3000009'
    When I execute this query, SQL Server 2000 has no problem with it, but the DB Tools Fetch Recordset Data vi only returns the first match. I think my answer may lie with OR statements. Rather than sending what amounts to potentially dozens of individual queries, I should be able to chain them into one query with a lot of OR statements. As long as the OR statement is not an exclusive OR statement, I think it should work. I haven't tried it yet, and it may take some time to get the syntax right. The query is built in a for loop with the number of iterations equal to the number of serial numbers being defined. Once I get this working I will alter it to include both upper and lower case letters that can be included in the query. Any suggestiona of how the query should be structured would be most helpful, or another way to achieve what I am trying to accomplish.
    SciManStev

Maybe you are looking for

  • Command for "How to find Cursor Size" in Oracle Stored Procedure"

    Hi Can u tell me.... How to find Cursor Size" in Oracle Stored Procedure........ I want command for that........

  • Question About repetition code

    There is a simple way write all this code? or make it easier?     label_01.setBorder(BorderFactory.createLineBorder(Color.black));     label_02.setBorder(BorderFactory.createLineBorder(Color.black));     label_03.setBorder(BorderFactory.createLineBor

  • Problems after updating to window 8.1

    I have a notebook Lenovo G510, I7. My problem is that when I update the windows system to windows 8.1, the system becomes instable. A lot of bug happens !!! Any help ???  Thank you in advance.

  • Organization Settings unable to update

    I am just starting with Office 365 and setting up the Exchange environment. When I try to make a change to retention tag and save it, I get the error: Sorry! We couldn't update your organization settings. Please try again. Click here for help... I we

  • I Movie doesn't Start up !! help

    MacBook Pro OS X (10.5.1) I have installed new Leopard and reinstalled ILife '08 but every time i launch IMovie it basically does not work !!! THis is what i Get ! Process: iMovie [1094] Path: /Applications/IWorld/iMovie.app/Contents/MacOS/iMovie Ide