Distinct query problem

Hi,
Does anyone know why this doesn't work?
USE LOGONs;
SELECT ComputerName, Description, Make, Model, Servicetag, [Serial Number], TagShipdate, OperatingSystem, startdate, enddate
FROM All_Warranties_Archive$
WHERE TagShipDate < DATEADD(dd,-1095,GETDATE())
GROUP By ServiceTag
The error I get is
Column 'All_Warranties_Archive$.ComputerName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

Hi,
This is the data I am getting back with JingLangli's query
NULL    stock        Dell    PRECISION M4300    19J***    NULL    2007-08-30 00:00:00.000    NULL    2007-08-29 00:00:00.000  
 2010-08-29 00:00:00.000
NULL    stock        Dell    PRECISION M4300    19J***    NULL    2007-08-30 00:00:00.000    NULL    2007-08-29 00:00:00.000  
 2010-08-29 00:00:00.000
NULL    stock        Dell    PRECISION M4300    19J***    NULL    2007-08-30 00:00:00.000    NULL    2007-08-29 00:00:00.000  
 2010-08-29 00:00:00.000
NULL    stock        Dell    PRECISION M4300    19J***    NULL    2007-08-30 00:00:00.000    NULL    2007-08-29 00:00:00.000  
 2010-08-29 00:00:00.000
NULL    stock        Dell    PRECISION M4300    19J***    NULL    2007-08-30 00:00:00.000    NULL    2007-08-29 00:00:00.000  
 2010-08-29 00:00:00.000
NULL    stock        Dell    OPTIPLEX 755    1FP***    NULL    2008-10-01 00:00:00.000    NULL    2008-09-30 00:00:00.000  
 2011-09-30 00:00:00.000
NULL    stock        Dell    OPTIPLEX 755    1FP***    NULL    2008-10-01 00:00:00.000    NULL    2008-09-30 00:00:00.000  
 2011-09-30 00:00:00.000
6th column along is the Service tag, there are multiple entries in this column and I'd like this to be the distinct or grouped by colum.  The only other colum I am interested in is the 8th column along, tagshipdate....  Tag ship date should all
be the same for each Service Tag...

Similar Messages

  • Issue with "Select Distinct" query in Oracle 10g against Oracle 9i

    Hi,
    I would appreciate if some one help me here because it is really urgent.
    We are upgrading our database from 9i to 10g.
    There are the "Select distinct" queries in the code which populated the grid on the applications screens. We found a difference in 9i and 10g the way the result is populated for these queries. If "Select Distinct" query wihtout a order by clause is executed in 9i then the result is automatically sorted. But Oracle 10g does not do this.
    We can change the queries adding order by clause but we are almost at the end of the testing and want to know if there is any way that we can do this from database settings. Would there be any impact of these settings change on overall operation of Oracle 10g?
    I would appreciate if some one can help me here.
    Thanks,
    Dinesh

    then the result is automatically sorted.No. Oracle may have done a sort operation to perform the distinct, but it still did not guarantee the order of your results.
    In 10g and in 9i, if you want your results in a certain order you must use order by.

  • Designing LOV Query Problem

    Hello APEX people,
    I posted my problem here:
    Designing LOV Query Problem
    What I have is a sequence like this:
    CREATE SEQUENCE
    DR_SEQ_FIRST_SCHEDULE_GROUP
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE ;
    What I need would be a SQL query returning all possible values oft my sequence like:
    1
    2
    3
    4
    5
    6
    7
    I want to use it as a source for a LOV...
    The reason why I use the cycling sequence is: My app uses it to cycle scheduling priorities every month to groups identified by this number (1-7).
    In the Admin Form, I want to restrict the assignment in a user friendly way - a LOV.
    Thanks
    Johann

    Here ist the solution (posted by michales in the PL/SQL forum):
    SQL> CREATE SEQUENCE
    dr_seq_first_schedule_group
    MINVALUE 1 MAXVALUE 7 INCREMENT BY 1 START WITH 1
    CACHE 6 ORDER CYCLE
    Sequence created.
    SQL> SELECT LEVEL sn
    FROM DUAL
    CONNECT BY LEVEL <= (SELECT max_value
    FROM user_sequences
    WHERE sequence_name = 'DR_SEQ_FIRST_SCHEDULE_GROUP')
    SN
    1
    2
    3
    4
    5
    6
    7
    7 rows selected.

  • SQL+-MULTI TABLE QUERY PROBLEM

    HAI ALL,
    ANY SUGGESTION PLEASE?
    SUB: SQL+-MULTI TABLE QUERY PROBLEM
    SQL+ QUERY GIVEN:
    SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
    HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
    DLC_POLYMORPHS_NORMAL_VALUE FROM PATIENTS_MASTER1, HAEMATOLOGY1,
    DIFFERENTIAL_LEUCOCYTE_COUNT1
    WHERE PATIENT_NUM = HMTLY_PATIENT_NUM AND PATIENT_NUM = DLC_PATIENT_NUM AND PATIENT_NUM
    = &PATIENT_NUM;
    RESULT GOT:
    &PATIENT_NUM =1
    no rows selected
    &PATIENT_NUM=2
    no rows selected
    &PATIENT_NUM=3
    PATIENT_NUM 3
    PATIENT_NAME KKKK
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 4
    HMTLY_RBC_NORMAL 4.6-6.0
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     60
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    ACTUAL WILL BE:
    &PATIENT_NUM=1
    PATIENT_NUM 1
    PATIENT_NAME BBBB
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 5
    HMTLY_RBC_NORMAL 4.6-6.0
    &PATIENT_NUM=2
    PATIENT_NUM 2
    PATIENT_NAME GGGG
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     42
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    &PATIENT_NUM=3
    PATIENT_NUM 3
    PATIENT_NAME KKKK
    HMTLY_TEST_NAME HAEMATOLOGY
    HMTLY_RBC_VALUE 4
    HMTLY_RBC_NORMAL 4.6-6.0
    DLC_TEST_NAME DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE     60
    DLC_POLYMORPHS_NORMAL_VALUE     40-65
    4 TABLES FOR CLINICAL LAB FOR INPUT DATA AND GET REPORT ONLY FOR TESTS MADE FOR PARTICULAR
    PATIENT.
    TABLE1:PATIENTS_MASTER1
    COLUMNS:PATIENT_NUM, PATIENT_NAME,
    VALUES:
    PATIENT_NUM
    1
    2
    3
    4
    PATIENT_NAME
    BBBB
    GGGG
    KKKK
    PPPP
    TABLE2:TESTS_MASTER1
    COLUMNS:TEST_NUM, TEST_NAME
    VALUES:
    TEST_NUM
    1
    2
    TEST_NAME
    HAEMATOLOGY
    DIFFERENTIAL LEUCOCYTE COUNT
    TABLE3:HAEMATOLOGY1
    COLUMNS:
    HMTLY_NUM,HMTLY_PATIENT_NUM,HMTLY_TEST_NAME,HMTLY_RBC_VALUE,HMTLY_RBC_NORMAL_VALUE     
    VALUES:
    HMTLY_NUM
    1
    2
    HMTLY_PATIENT_NUM
    1
    3
    MTLY_TEST_NAME
    HAEMATOLOGY
    HAEMATOLOGY
    HMTLY_RBC_VALUE
    5
    4
    HMTLY_RBC_NORMAL_VALUE
    4.6-6.0
    4.6-6.0
    TABLE4:DIFFERENTIAL_LEUCOCYTE_COUNT1
    COLUMNS:DLC_NUM,DLC_PATIENT_NUM,DLC_TEST_NAME,DLC_POLYMORPHS_VALUE,DLC_POLYMORPHS_
    NORMAL_VALUE,
    VALUES:
    DLC_NUM
    1
    2
    DLC_PATIENT_NUM
    2
    3
    DLC_TEST_NAME
    DIFFERENTIAL LEUCOCYTE COUNT
    DIFFERENTIAL LEUCOCYTE COUNT
    DLC_POLYMORPHS_VALUE
    42
    60
    DLC_POLYMORPHS_NORMAL_VALUE
    40-65
    40-65
    THANKS
    RCS
    E-MAIL:[email protected]
    --------

    I think you want an OUTER JOIN
    SELECT PATIENT_NUM, PATIENT_NAME, HMTLY_TEST_NAME, HMTLY_RBC_VALUE,
    HMTLY_RBC_NORMAL_VALUE, DLC_TEST_NAME, DLC_POLYMORPHS_VALUE,
    DLC_POLYMORPHS_NORMAL_VALUE
    FROM PATIENTS_MASTER1, HAEMATOLOGY1,  DIFFERENTIAL_LEUCOCYTE_COUNT1
    WHERE PATIENT_NUM = HMTLY_PATIENT_NUM (+)
    AND PATIENT_NUM = DLC_PATIENT_NUM (+)
    AND PATIENT_NUM = &PATIENT_NUM;Edited by: shoblock on Nov 5, 2008 12:17 PM
    outer join marks became stupid emoticons or something. attempting to fix

  • Date range query  problem  in report

    Hi all,
    I have created a report based on query and i want to put date range selection but query giving problem.
    If i am creating select list selection then it is working fine means it will display all records on the particular date.
    But what i need is that user will enter date range as creation_date1,creation_date2 and query should return all the records between these date range. i want to pass it by creating items, i created two items and passing creation_date range to display all records but not displaying and if not passing date then should take null as default and display all records
    Here is the query:
    /* Formatted on 2006/12/10 20:01 (Formatter Plus v4.8.0) */
    SELECT tsh."SR_HEADER_ID", tsh."SALES_DEPT_NUMBER", tsh."COUNTRY",
    tsh."LOCAL_REPORT_NUMBER", tsh."ISSUE_DATE", tsh."SUBJECT",
    tsh."MACHINE_SERIAL_NUMBER", tsh."MACHINE_TYPE", tsh."MACHINE_HOURS",
    tsh."STATUS"
    FROM "TRX_SR_HEADERS" tsh, "TRX_SR_PARTS" tsp
    WHERE (tsh.status LIKE :p23_status_sp OR tsh.status IS NULL)
    AND (tsh.machine_type LIKE :p23_machine_type_sp)
    AND ( tsh.machine_serial_number LIKE
    TO_CHAR (:p23_machine_serial_number_sp)
    OR tsh.machine_serial_number IS NULL
    AND ( TO_CHAR (tsh.failure_date, 'DD-MON-YY') LIKE
    TO_CHAR (:p23_failure_date_sp)
    OR TO_CHAR (tsh.failure_date, 'DD-MON-YY') IS NULL
    AND ( TO_CHAR (tsh.creation_date, 'DD-MON-YY')
    BETWEEN TO_CHAR (:p23_creation_date_sp)
    AND TO_CHAR (:p23_creation_date_sp1)
    OR TO_CHAR (tsh.creation_date, 'DD-MON-YY') IS NULL
    AND (tsh.issue_date LIKE :p23_date_of_issue_sp OR tsh.issue_date IS NULL)
    AND (tsh.country LIKE :p23_country_sp OR tsh.country IS NULL)
    AND ( tsh.local_report_number LIKE TO_CHAR (:p23_local_rep_num_sp)
    OR tsh.local_report_number IS NULL
    AND ( tsp.part_number LIKE TO_CHAR (:p23_part_number_sp)
    OR tsp.part_number IS NULL
    AND tsh.machine_type IN (
    SELECT DISTINCT machine_type
    FROM trx_sales_dept_machine_list
    WHERE sales_department_id IN (
    SELECT DISTINCT sales_department_id
    FROM trx_user_sales_department
    WHERE UPPER (user_name) =
    UPPER ('&APP_USER.'))
    AND SYSDATE >= valid_from)
    AND tsh.sr_header_id = tsp.sr_header_id
    can any one tell me wat is wroung in this query.
    Any other way to write this?
    Thank You,
    Amit

    Hi User....
    Here is some date range SQL that my teams uses with some success:
    For date columns that do not contain NULL values, try this (note the TRUNC, it might help with your "today" problem).
    The hard coded dates allow users to leave the FROM and TO dates blank and still get sensible results (ie a blank TO date field asks for all dates in the future.
    AND TRUNC(DATE_IN_DATABASE)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),:
    :P1_DATE_TO)
    For date columns that contain NULL values, try this (a little bit trickier):
    AND nvl(TRUNC(DATE_IN_DATABASE),
    decode( :P1_DATE_FROM,
    decode( :P1_DATE_TO,
    TO_DATE('30-DEC-3000'),
    NULL),
    NULL)
    BETWEEN
    decode( :P1_DATE_FROM,
    TO_DATE('01-JAN-1900'),
    :P1_DATE_FROM)
    AND
    decode( :P1_DATE_TO,
    TO_DATE('31-DEC-3000'),
    :P1_DATE_TO)
    Note the 30-DEC-3000 versus 31-DEC-3000. This trick returns the NULL dates when the FROM and TO date range items are both blank.
    I hope this helps.
    By the way, does anyone have a better way of doing this? The requirement is given a date column in a database and a FROM and a TO date item on a page,
    find all of the dates in the database between the FROM and TO dates. If the FROM date is blank, assume the user want all dates in the past (excluding NULL dates). If the TO date is blank, assume that the user wants all of the dates in the future (excluding NULL dates). If both FROM and TO dates are blank, return all of the dates in the databse (including NULL dates).
    Cheers,
    Patrick

  • Interactive Report and DISTINCT keyword problem

    Hi,
    I am having a strange problem
    The following query works fine in SQL Developer and return ONLY 202 records.
    SELECT distinct "ATT_WARNINGS"."ID", "ATT_WARNINGS"."WARNING_NUM", "ATT_WARNINGS"."ISSUED", "ATT_WARNINGS"."ISSUED_DATE", "ATT_WARNINGS"."STDN_ID", "ATT_WARNINGS"."TOTAL_MISSED", "ATT_WARNINGS"."ISSUED_BY", "ATT_WARNINGS"."TERM_CODE_KEY", "ATT_VETI"."BLOCK_GROUP", "ATT_VETI"."STDN_NAME"
    bq. FROM "ATT_WARNINGS", "ATT_VETI"
    bq. bq. WHERE ( "ATT_VETI"."STDN_ID" = "ATT_WARNINGS"."STDN_ID" ) \\ AND ( "ATT_WARNINGS"."TERM_CODE_KEY" = '200920') \\ AND ("ATT_VETI"."BLOCK_GROUP" LIKE '%Day')
    When using that in Interactive Report I get the following:
    {color:#ff0000}+This query returns more then 10,000 rows, please filter your data to ensure complete results.+
    {color:#000000}Looks like the IR does not understand the keyword DISTINCT
    Can you help me guys?
    Thank you
    {color}{color}

    I must be sleepy.
    I was setting the max row count to 25 only!!
    I changed to 1000 and it works now :)

  • Approval Tempate Terms Query Problem

    I have a query that i've included in the Approval Tempate - Terms Tab, that checks to see if any order lines after discount price is less than a Item UDF minimum price for the item. It is as follows:
    SELECT DISTINCT 'True'
    FROM  [dbo].[ORDR] T0 (nolock)
    INNER  JOIN [dbo].[RDR1] T1 (nolock) ON  T1.[DocEntry] = T0.[DocEntry]  
    inner  join [dbo].[OITM] T3 (nolock) on T3.ItemCode = t1.itemCode
    where T0.[DocNum] = $[ORDR.DocNum]
    and T1.INMPrice <= T3.U_LBSiMinPrice
    My problem is that the Approval is not kicking off no matter the outcome of the query. Meaning if the price is < the minimum price or > the minimum price, the approval pop-up window does not appear.

    Hi Scott,
    B1 does not support approval queries on document lines. you can query only document header.
    you can either try to workaround it with all sorts of aggregate UDFs in the header, or alternatively take a look at:
    [http://www.beonesolutions.com/ip/Solutions/ap.html|http://www.beonesolutions.com/ip/Solutions/ap.html]
    all details, including the ability to query all document tables, are in:
    [http://www.beonesolutions.com/files/Approval_Pro_Brochure.pdf|http://www.beonesolutions.com/files/Approval_Pro_Brochure.pdf]
    Gilan

  • JPA query problem

    Hi folks !
    I have this class with TemporalType.DATE property
    and i want to know if the query i design should look like this:
    select a from A a where a.dateProp = :theDateis this sufficient (where theDate should be substituted with a java.util.Date object with only the date,month,year set)?
    thanks

    Yes. In fact, the problem I've posted is a generalization of a more strange behaviur. The (cutted-off) schema is
    Table Charter
    id       integer   primary key
    company  integer   foreign key (on 'id' of table 'company')
    price    decimal
    Table Company
    id       integer   primary key
    name     textNow, assume I have 10 records in table Charter referencing 10 records in table Company (each row in Charter reference a distinct row in Company).
    This query returns me THE CORRECT RESULT (that is, each matching row is present in the result set only once):
    SELECT o FROM Charter AS o WHERE o.company.id = :company AND 1=1Instead, this query returns me each matching row, BUT REPEATED N TIMES, where N is the number of rows in Charter (10):
    SELECT o FROM Charter AS o WHERE 1=1 AND o.company.id = :company(Notice that the only difference is the order of the where clause)
    (Notice also that I get the same behaviour even if I do a query on the 'price' field).
    Also, this query that should return all the rows in the table (one time each), returns them N times:
    SELECT o FROM Charter AS o WHERE 1=1Any idea?
    Really thank you
    ps I forgot to say that, after translating those JPQL query in standard SQL and executing them in PostgreSQL console, they are, obiouvsly, equivalent and work correctly.
    Message was edited by:
    Konrad84

  • 10g Dev Preview -- sub query problem

    I'm not sure if this is the place to report bugs or problems with the 10g developer preview. But here goes.
    I have some code that used to work. The idea is to find "task" objects that are not assigned to anyone, ie, have no "task assignment" records pointing to them. This code used to work. It creates an expression that when queried returns all Task objects that are not in the subQuery which fetches task assignments.
    ExpressionBuilder eb = new ExpressionBuilder();
    ReportQuery queryAssigned = new ReportQuery(TaskAssignment.class, new ExpressionBuilder());
    ReportQuery queryAssigned = new ReportQuery(TaskAssignment.class, new ExpressionBuilder());
    queryAssigned.addAttribute("ID", eb.get("task").get("ID"))
    return eb.get("ID").notIn(eb.subQuery(queryAssigned));
    When I use TOPLink 10g, however, I get the following error:
    [junit] Query: ReadAllQuery(com.marketsoft.workflow.Task)
    [junit] Local Exception Stack:
    [junit] Exception [TOPLINK-6015] (Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)): oracle.toplink.ex
    ceptions.QueryException
    [junit] Exception Description: Invalid query key [task] in expression.
    [junit] Query: ReadAllQuery(com.marketsoft.workflow.Task)
    [junit] at oracle.toplink.exceptions.QueryException.invalidQueryKeyInExpression(QueryException.java:491)
    [junit] at oracle.toplink.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:555)
    [junit] at oracle.toplink.expressions.Expression.normalize(Expression.java:2587)
    [junit] at oracle.toplink.internal.expressions.DataExpression.normalize(DataExpression.java:349)
    [junit] at oracle.toplink.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:369)
    [junit] at oracle.toplink.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:356)
    [junit] at oracle.toplink.internal.expressions.DataExpression.normalize(DataExpression.java:343)
    [junit] at oracle.toplink.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:369)
    [junit] at oracle.toplink.internal.expressions.QueryKeyExpression.normalize(QueryKeyExpression.java:356)
    [junit] at oracle.toplink.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:951)
    [junit] at oracle.toplink.internal.expressions.SubSelectExpression.normalizeSubSelect(SubSelectExpression.java:123)
    [junit] at oracle.toplink.internal.expressions.ExpressionNormalizer.normalizeSubSelects(ExpressionNormalizer.java:82)
    [junit] at oracle.toplink.internal.expressions.SQLSelectStatement.normalize(SQLSelectStatement.java:982)
    [junit] at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.buildNormalSelectStatement(ExpressionQuery
    Mechanism.java:223)
    [junit] at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.prepareCursorSelectAllRows(ExpressionQuery
    Mechanism.java:587)
    [junit] at oracle.toplink.queryframework.CursorPolicy.prepare(CursorPolicy.java:137)
    [junit] at oracle.toplink.queryframework.CursoredStreamPolicy.prepare(CursoredStreamPolicy.java:93)
    [junit] at oracle.toplink.queryframework.ReadAllQuery.prepare(ReadAllQuery.java:571)
    [junit] at oracle.toplink.queryframework.DatabaseQuery.checkPrepare(DatabaseQuery.java:367)
    [junit] at oracle.toplink.queryframework.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:506)
    [junit] at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:537)
    [junit] at oracle.toplink.queryframework.ReadAllQuery.execute(ReadAllQuery.java:408)
    [junit] at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:1977)
    [junit] at oracle.toplink.publicinterface.Session.executeQuery(Session.java:973)
    This maybe isn't that surprising. I see that the unbound ExpressionBuilders might be causing problems. However, which I switch to something a little bit more like what I see in the examples:
    ExpressionBuilder eb = new ExpressionBuilder();
    ExpressionBuilder assignBuilder = new ExpressionBuilder();
    ReportQuery queryAssigned = new ReportQuery(TaskAssignment.class, assignBuilder);
    queryAssigned.addAttribute("ID", assignBuilder.get("task").get("ID"));
    queryAssigned.useDistinct();
    return eb.get("ID").notIn(eb.subQuery(queryAssigned));
    In this case, it seems to generate messed up SQL where the table name goes missing:
    Exception [TOPLINK-4002] (Oracle TopLink - 10g Developer Preview 3 (10.1.3.0 ) (Build 041116)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: ORA-00903: invalid table name
    Error Code: 903
    Call:SELECT COUNT(*) FROM TASKS t0 WHERE ((t0.ID NOT IN (SELECT DISTINCT t1.ID FROM )) AND (t0.ITEMTYPE = ?))
         bind => [Task]
    Query:ReportQuery(com.marketsoft.workflow.Task)
    Local Exception Stack:

    Charles,
    I couldn't reproduce your problem. I used an employee example in which Employee has 1:m relationship with PhoneNumber. My code and sql are as follows:
         ReadAllQuery query = new ReadAllQuery(Employee.class);
         ExpressionBuilder emp = new ExpressionBuilder(Employee.class);
         ExpressionBuilder phone = new ExpressionBuilder();
         ReportQuery subquery = new ReportQuery(PhoneNumber.class, phone);
         subquery.addAttribute("id", phone.get("owner").get("id"));
         subquery.useDistinct();
         Expression expression = emp.get("id").notIn(subquery);
         query.setSelectionCriteria(expression);
    Vector employees = (Vector)getSession().executeQuery(query);
    SELECT t0.VERSION, t1.EMP_ID, t0.L_NAME, t0.F_NAME, t1.SALARY, t0.EMP_ID, t0.GENDER, t0.END_DATE, t0.START_DATE, t0.MANAGER_ID, t0.START_TIME, t0.END_TIME, t0.ADDR_ID FROM EMPLOYEE t0, SALARY t1 WHERE ((t0.EMP_ID NOT IN (SELECT DISTINCT t2.EMP_ID FROM PHONE t4, SALARY t3, EMPLOYEE t2 WHERE ((t2.EMP_ID = t4.EMP_ID) AND (t3.EMP_ID = t2.EMP_ID)))) AND (t1.EMP_ID = t0.EMP_ID))
    Shanno

  • LOV query problem (1.6)

    Hi,
    I have been pulling my hair out over this one!
    Background: I have an LOV that needs to return 4 different lists depending which of 4 radio buttons (P40_OPPORTUNITY_TOGGLE) has been selected, and who is logged in (FLOW_USER).
    the LOV of based off two views:
    * OPP_GEO_V (opportunity, sales consultant and geography for opp)
    SC_EMAIL_ADDRESS
    OPP_NUMBER
    OPPORTUNITY
    CUSTOMER
    DIVISION
    REGION
    COUNTRY
    * SC_GEO_V (sales consultant and geography for SC)
    EMAIL_ADDRESS
    DIVISION
    REGION
    COUNTRY
    SALES_ACCESS
    The four lists should be:
    * All opportunities in the same country as the user
    * All opportunities in the same region as the user (depending on SALES_ACCESS)
    * All opportunities in the same division as the user (depending on SALES_ACCESS)
    * Every opportunity where the user is listed against it (SC_EMAIL_ADDRESS)
    The query:
    select distinct o.opp_number||' - '||o.customer||' - '||o.opportunity d, o.opp_number||' - '||o.customer||' - '||o.opportunity r
    from opp_geo_v o, sc_geo_v s
    where
    (nvl(:P40_OPPORTUNITY_TOGGLE,'C') = 'C'
    AND upper(s.email_address) = upper(:FLOW_USER)
    and o.country = s.country)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'R'
    AND upper(s.email_address) = upper(:FLOW_USER)
    AND s.sales_access is not null
    and o.region = s.region)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'D'
    AND upper(s.email_address) = upper(:FLOW_USER)
    AND s.sales_access = 'D'
    AND o.division = s.division)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'S'
    AND upper(o.sc_email_address) = upper(:FLOW_USER))
    Problem: HTML DB will time out when trying to submit this query. The strange thing is, it was functioning well until last night when I added the final OR block (opp_toggle = 'S'). If i remove the first 3 OR blocks, it will submit fine. If I remove the bottom OR block it will also submit fine. But for some reason it won't allow me to have all 4. Actually it won't allow any combination of the bottom OR block and any of the top 3...
    This could be something blatantly obvious or it might just be one of those oddities, but I'd appreciate any ideas.
    Thanks,
    Mark

    Ok I changed FLOW_USER to APP_USER, i think in this case it will be the same value (email address), and the functionality of the LOV is still the same, but if you insist =)
    Now this is odd and may give an idea of what is going on.....
    I have a table ALL_CLIENTS, which is one of the tables that makes up the view OPP_GEO_V (geographic_areas being the other). The fields that come from ALL_CLIENTS are:
    * SC_EMAIL_ADDRESS
    * OPP_NUMBER
    * OPPORTUNITY
    * CUSTOMER
    now, if i alter the query so I pull the data from ALL_CLIENTS, and use OPP_GEO_V for looking up the geographic information for the opportunity (with a join between ALL_CLIENTS and OPP_GEO_V --- o.opp_number = c.opp_number) in each of the OR clauses, it WORKS! It sounds ridiculous that I'm joining a view with one of the tables it's based off, but i'm getting desparate here... This is probably a confusing description, so here's the query:
    select distinct c.opp_number||' - '||c.customer||' - '||c.opportunity d, c.opp_number||' - '||c.customer||' - '||c.opportunity r
    from opp_geo_v o, sc_geo_v s, all_clients c
    where
    (nvl(:P40_OPPORTUNITY_TOGGLE,'C') = 'C'
    AND upper(s.email_address) = upper(:APP_USER)
    and o.opp_number = c.opp_number
    and o.country = s.country)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'R'
    AND upper(s.email_address) = upper(:APP_USER)
    AND s.sales_access is not null
    and o.opp_number = c.opp_number
    and o.region = s.region)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'D'
    AND upper(s.email_address) = upper(:APP_USER)
    AND s.sales_access = 'D'
    and o.opp_number = c.opp_number
    AND o.division = s.division)
    OR
    (:P40_OPPORTUNITY_TOGGLE = 'S'
    AND upper(c.sc_email_address) = upper(:APP_USER)
    and o.opp_number = c.opp_number)
    As you can see, I no longer have to look up OPP_GEO_V to compare the email address in the bottom OR clause.. but why on earth would HTML DB object to me doing that? I feel like I'm looking in the wrong spot here...
    The only problem with this is it's unacceptably slow. There are currently 836 sales consultant records and 95718 opportunity records, which will be growing significantly once this goes into production, so I kinda need it to be speedy!
    I hope this post hasn't caused confusion ....
    Mark

  • Hierachy Query problem

    Hi all,
    I have some problem of retrieving sql from two table using Hierachy Query.
    Below is two table and excepted table and my query.
    I cannot be think how to join and query to get result_table
    Please kindly repair and guid me. Thank.
    table_1
    DATA_DT_ID MKT_TYPE_IND      DATA_DT    CONS_WGT   INDEX_ID INDEX_CODE CONS_CODE
    20060331     1     31/03/2006     1     -1002     IDX_1B          -1
    20060331     2     31/03/2006     1     -1002     IDX_1B          -1
    20060331     1     31/03/2006     0.7     -1001     IDX_1A          -2
    20060331     2     31/03/2006     0.7     -1001     IDX_1A          -2
    20060331     1     31/03/2006     0.3     -1001     IDX_1A          -1
    20060331     2     31/03/2006     0.3     -1001     IDX_1A          -1
    20060401     1     01/04/2006     1     -1003     IDX_1C          -2
    20060402     1     02/04/2006     1     -1003     IDX_1C          -2
    20060401     2     01/04/2006     1     -1003     IDX_1C          -2
    20060402     2     02/04/2006     1     -1003     IDX_1C          -2
    20060401     1     01/04/2006     1     -1002     IDX_1B          -1
    20060402     1     02/04/2006     1     -1002     IDX_1B          -1
    20060401     2     01/04/2006     1     -1002     IDX_1B          -1
    20060402     2     02/04/2006     1     -1002     IDX_1B          -1
    20060401     1     01/04/2006     0.7     -1001     IDX_1A          -2
    20060402     1     02/04/2006     0.7     -1001     IDX_1A          -2
    20060401     2     01/04/2006     0.7     -1001     IDX_1A          -2
    20060402     2     02/04/2006     0.7     -1001     IDX_1A          -2
    20060401     1     01/04/2006     0.3     -1001     IDX_1A          -1
    20060402     1     02/04/2006     0.3     -1001     IDX_1A          -1
    20060401     2     01/04/2006     0.3     -1001     IDX_1A          -1
    20060402     2     02/04/2006     0.3     -1001     IDX_1A          -1
    table_2
    DATA_DT  CHILD_INDEX_WGT MKT_TYPE_IND INDEX_ID CHILD_INDEX_ID INDEX_CODE CHILD_INDEX_CODE
    31/03/2006     0.3          2      -3001          -1001      IDX_3A          IDX_1A
    31/03/2006     0.7          2      -3001          -1002      IDX_3A          IDX_1B
    31/03/2006     0.2          2      -3002          -1001      IDX_3B          IDX_1A
    31/03/2006     0.8          2      -3002          -1003      IDX_3B          IDX_1C
    31/03/2006     0.5          2      -3003          -3001      IDX_3C          IDX_3A
    01/04/2006     0.3          2      -3001          -1001      IDX_3A          IDX_1A
    01/04/2006     0.7          2      -3001          -1002      IDX_3A          IDX_1B
    01/04/2006     0.2          2      -3002          -1001      IDX_3B          IDX_1A
    01/04/2006     0.8          2      -3002          -1003      IDX_3B          IDX_1C
    01/04/2006     0.5          2      -3003          -3001      IDX_3C          IDX_3A
    01/04/2006     0.5          2      -3003          -3002      IDX_3C          IDX_3B
    Result_table
    DATA_DT    INDEX_CODE CHILD_INDEX_CODE CONS_CODE MKT_TYPE_IND BLENDED_WGT
    31/03/2006  IDX_3C     IDX_1B          -1        2          5*.7*1
    31/03/2006  IDX_3A     IDX_1B          -1        2          7*1
    31/03/2006  IDX_3C     IDX_1A          -2        2          5*.3*.7
    31/03/2006  IDX_3A     IDX_1A          -2        2          3*.7
    31/03/2006  IDX_3C     IDX_1A          -1        2          5*.3*.3
    31/03/2006  IDX_3A     IDX_1A          -1        2          3*.3
    01/04/2006  IDX_3C     IDX_1C          -2        2          5*.8*1
    01/04/2006  IDX_3B     IDX_1C          -2        2          8*1
    01/04/2006  IDX_3C     IDX_1B          -1        2          5*.7*1
    01/04/2006  IDX_3A     IDX_1B          -1        2          7*1
    01/04/2006  IDX_3C     IDX_1A          -2        2          5*.2*.7
    01/04/2006  IDX_3C     IDX_1A          -2        2          5*.3*.7
    01/04/2006  IDX_3B     IDX_1A          -2        2          2*.7
    01/04/2006  IDX_3A     IDX_1A          -2        2          3*.7
    01/04/2006  IDX_3C     IDX_1A          -1        2          5*.2*.3
    01/04/2006  IDX_3C     IDX_1A          -1        2          5*.3*.3
    01/04/2006  IDX_3B     IDX_1A          -1        2          2*.3
    01/04/2006  IDX_3A     IDX_1A          -1        2          3*.3with m_que as
    select distinct wei.data_dt,wei.index_code, wei.child_index_code, con.index_code child_child_index,
    wei.child_index_wgt, con.cons_wgt child_child_wgt,con.cons_code, con.mkt_type_ind
    from table_1 wei
    join table_2 con on wei.data_dt = con.data_dt
    where con.index_code < wei.child_index_code
    i_que as
    select data_dt, index_code, child_index_code, cons_code, mkt_type_ind,
    substr(SYS_CONNECT_BY_PATH(gs_child_index_wgt, '*'),3) BLENDED_WGT
    from (m_que)
    start with index_code = 'IDX_3C'
    connect by prior child_index_code = index_code
    select data_dt,index_code,child_index_code,cons_code,mkt_type_ind,BLENDED_WGT from i_que;

    Hi,
    Thank for your suggestion, but it is not work, when i put my query the result is nothing display.
    Another problem is i_que portion
    SYS_CONNECT_BY_PATH() can only retrieve BLENDED_WGT level is only 2nd level. Actual Result_table of BLENDED_WGT display 3rd level.
    I doubt is because of main select portion or all my query is wrong.
    Thanks

  • SQL date query problem with century/ year

    We have an oracle database with about 6 million records. There is a date field called Entered Date that ranges from 1985 to the present.
    The majority of these records were entered prior to Jan 1 2000.
    If I run a query like
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 0
    if I do
    select count(*) from (tablename) where entered_date < '31-DEC-99' I get 0
    BUT IF I DO
    select count(*) from (tablename) where entered_date < '01-JAN-00' I get 6 million records
    or
    select count(*) from TREASURY.ctrc where entrydate > '31-DEC-99' I get 6 million records
    I've tried the same queries using 4 digit years but get the same results; it thinks that 2000 is the less than 1999
    How do I get around this?
    thanks

    Hi,
    975204 wrote:
    there are 6 million records on the table
    about two thirds have a date prior to Jan 1 , 2000How do you know that? From knowledge of the application, you may know that two thirds of them are supposed to have dates prior to 2000, but if
    SELECT  COUNT (*)
    FROM      TABLE_NAME
    WHERE      ENTRYDATE < TO_DATE ( '01-JAN-2000'
                           , 'DD-MON-YYYY'
    ;returns 0, that's pretty strong proof that none of them actually do.
    When I look at the dates , they display as 31-DEC-86Another example of why using 2-digit years is such a bad idea.
    I cant actually provide dump of this clients confidential dataSeriously; you can't provide one DUMP output? You've already said that it displays as 31-DEC-86, so even if the fact that 1 entry in the 6-million row table was done on December 31, 1986 was such a big secret, it's already out, and you won't be causing any more harm by showing the DUMP results.
    I ran the query with the same format as the date ie
    SELECT COUNT(*) FROM TREASURY.CTRC WHERE ENTRYDATE < TO_DATE ( '31-DEC-99'
    , 'DD-MON-YY'
    but same results
    if the column is defined as a DATE type, does Oracle make a distinction based on how the data displays, meaning does it think that 31-DEC-86 is different than 31-DEC-1986?No, all DATE columns have the same format. A DATE may be displayed one way of the other, but it is stored as neither.
    Do I need to convert all the data to a 4 digit year? You should always display dates with a 4-digit year.
    Run an update query that says if year >= 80 and <= 99 add 19 in front of the year, else add 20 in front of the yearLet's find out exactly what the problem is, first.
    Did you see Ascheffer's message? ^1^ It was dated just a couple of minutes before your last message, so you might not have noticed it. Run it to see what the actual 4-digit years are.
    If it shows, for example, that there are a lot of entrydates in the years 2080 to 2099, and you decide that all of those really should be 100 years earlier, then use ADD_MONTHS to correct them:
    UPDATE     table_name
    SET     entrydate = ADD_MONTHS ( entrydate
                               , -100 * 12
    WHERE   entrydate >= TO_DATE ( '01-JAN-2080'
                             , 'DD-MON-YYYY'
    AND     entrydate <  TO_DATE ( '01-JAN-2100'
                             , 'DD-MON-YYYY'
    ;Edited by: Frank Kulash on Mar 15, 2013 6:09 PM
    ^1^ Obviously, you did see Ascheffer's message; I was still typing the message above when you posted another one.

  • Reg: Query Problem for New Posting Period

    Hi Xperts,
    While I try to Map the A/P Invoices with their respective Outgoing Payment,
    I used the following Query and it's Query Printlayout
    SELECT T0.DocNum [Payment#], T0.DocDate [Payment Date],
    T0.CardCode, T0.CardName, T1.InvoiceId, T2.DocNum [AP Inv#],
    T2.NumatCard [Bill No.], T2.DocDate [Bill Date], T1.selfInv,
    T1.SumApplied, T1.WtAppld, T0.NoDocsum 
    FROM  [dbo].[OVPM] T0  INNER  JOIN
    [dbo].[VPM2] T1  ON  T1.[DocNum] = T0.DocNum
    INNER  JOIN [dbo].[OPCH] T2  ON  T2.[DocEntry] = T1.DocEntry
    WHERE T0.Cardname='[%0]' and T0.DocDate='[%1]' and
    T0.DocNum='[%2]'
    I got the above query from our Expert Mr.Sambath only.
    Now what is the problem is the query is retrieving the payment details of old Posting Period only and not the current posting period.
    In detail, I used 'Primary' Series for FY08-09, Period indicator 'Default'
    Now I'm using 'Primary1' Series for FY09-10, Period indicator '0910'
    Thanx in adv.
    Regards,
    Bala

    Hi Bala,
    Looking at your query, it is not query issue ,it is your data issue.
    Please check if you have data in  VPM2  table  which is bank transfer payment method
    Thank you
    Bishal
    Edited by: Bishal Adhikari on Apr 9, 2009 8:48 AM

  • VIEW Query Problem

    Hi Greg,
    I had created a view on a table which doesn't have Primary Key, but it has Unique and Not Null constraints on required columns.
    I had wrote a procedure to query the data on VIEW. I have experienced strange problem, very first call to procedure will take more time than succeeding requests. For example from second request onwards, it returns data in < 2 Sec, but first transaction is taking 12 Sec to 30 Sec.
    I thought that very first time VIEW is taking time to refresh it self. So, I added FORCE keyword in CREATE VIEW stattement. However, that doesn't helped out.
    In my further investigation I came to know that base table on which VIEW created, has to be loaded in to memory before querying on VIEW.
    So, I had executed a simple select statement on base table, before I execute VIEW query in procedure.
    With this change I got results consistently < 2 Sec all the times.
    My question is instead of executing the select statement on base table is there a way to load base tables data in memory before querying on VIEW?
    Thanks,
    Subbarao

    Hi,
    A view is nothing but parsed SQL statements stored in the database, a view may or may not run faster. If you execute the SQL used to define the view how much time is it taking. If you want try looking at MATERIALIZED VIEW , that may help you.
    thanks

  • Multiprovider Query Problem

    Hi Gurus,
    The scenario is that there are 2 inficubes, one with order data and other with delivery data. The cube with order data has the requested delivery date and the delivery cube has the actual delivery date. The problem is that I have a query on a multiprovider (on top of the 2 cubes). So when I output the query data by the sales order number, the result is fine, but when I drill down on any of the dates mentioned above ( they are free characteristics in the query), the result splits up into 2 records. For Eg.
    Sales Order     Req Del Date  Act Del Date  Order Qty  Shipped Qty
    12345               03/03/08         -                    5                 -
                                   -           06/03/08            -                5
    What can I do to get the result in one row?
    I will reward points for any help.
    Thanks

    This is the behavior of the multiprovider, since the actual goods issue date is not part of the orders cube, then it will create a second record. There are a couple solutions you could get around to this:
    1. You could merge the data in one DSO before you actually load it to the data target. To do this, you could update fields you need to the orders ods from the delivery ods.
    2. You could create an infoset between the two cubes if you are in 7.0, otherwise, you could create infoset using the underlying ods and create a query from the infoset: performance wise this is not recommended.
    3. If you want to solve the issue report level, there is what is called constant selection and you can make the actual goods issue date as a constant selection and you can get one line.
    /people/prakash.darji/blog/2006/09/19/the-hidden-secret-of-constant-selection
    I would recommend the last option,
    thanks.
    Wond

Maybe you are looking for