Toplink issues select distinct type query before fetch

When we have type classifiers identified by value, Toplink issues a 'SELECT DISTINCT TYPE' on the parent object and then queries the child records for that type, is there way to avoid the select distinct
type query from Toplink in queries, this is slowing down the query performance. thanks

More info
This is the Report Query:
Session session = PersistenceFactory.newSession();
ExpressionBuilder eb = new ExpressionBuilder();
ReportQuery query = new ReportQuery( eb );
query.setReferenceClass( FXSingleLegDealC.class );
query.useCollectionClass( ArrayList.class );
query.setSelectionCriteria( eb.get( "objectID" ).equal( 249994 ) );
query.addAttribute( "objectID", eb.get( "objectID" ) );
query.addAttribute( "parentDealFXDealLegCurrency1Amount", eb.get( "dealFXSingleLegParent" ).get( "fxDealLeg" ).get( "currency1Amount" ) );
query.addAttribute( "parentDealFXDealLegCurrency1Amount", eb.get( "dealFXSingleLegParent" ).get( "fxDealLeg" ).get( "currency2Amount" ) );
query.addAttribute( "parentDealFXDealLegCurrency1Amount", eb.get( "dealFXSingleLegParent" ).get( "fxDealLeg" ).get( "currency1" ).get( NamedEntity.ShortName) );
query.addAttribute( "parentDealFXDealLegCurrency1Amount", eb.get( "dealFXSingleLegParent" ).get( "counterpartyA" ).get( NamedEntity.ShortName) );
ArrayList result = ( ArrayList ) session.executeQuery( query );
This is the SQL Generated:
SELECT t0.id, t1.ccy1Amt, t1.ccy2Amt, t2.shortName, t3.shortName FROM IdcCpty t3, IdcInstr t2, IdcDeal t1, IdcDeal t0
WHERE (((t0.id = ?) AND (t0.type = ?)) AND ((((t1.id = t0.parentId) AND (t1.type = ?)) AND ((t2.id = t1.ccy1Id) AND (t2.type = ?))) AND ((t3.id = t1.cptyAId) AND (t3.type = ?))))
bind => [249994, IdcFXSLegDealC, IdcFXSLegDealC, IdcCrncC, IdcLglEntC]
Not sure why we need to query for type on t2 and t3 after we have made a join by id (t2.id = t1.ccy1Id,t3.id = t1.cptyAId), this is really breaking our performance, we do not want to add an index on
the type column
can someone please respond!?

Similar Messages

  • Issue while writing a query in table type select.in the physical layer

    Hi gurus,
    I am actually trying to create a table using select in the physical layer..... i acutally am not aware what it is called but its when i click a table in the physical layer i have an option table type and i chose select which allows me type my query..the query is
    Select
    coln name(which is a lengthly list of conversion) AS column_name
    From Table name.
    when i view the data rom the physical layer everthing seems to be fine. but when i try to view the data in the frnt end it gives me an error maximum length is too long than 128....
    i am aware of this issue the sql server allows only column of length 128..but none of my column length is greater than 128..
    Could you please help me in this
    Many thanks in advance

    hi veeravalli ,
    Thanks for the reply....actually the corresponding reports for this have already been prepared...i created a view in the backend with the same select which i wrote before and and tried calling the view from her.. i have viewed the data and all is perfect...but when i try viewing it from the front end it error saying invaild object name select * from databasename.dbo.View_name...but i have checked the view exists in the backend...
    Thanks in advance....

  • Issue with select query to fetch data using Join from two tabels

    Hello All-
    I want to fetch the ShowName as "SUN NIGHTLY NEWS" and EpisodeName as "091706"
    based on the condition a.TitleNo=b.TitleNo and a.seriesNo=b.TitleNo.
    If i use the only first condition-a.TitleNo=b.TitleNo than output is displayed as-
    SchedItemNo |      Showname|      EpisodeName
    2702154     |     091706     |     091706
    If i use the second Condition-a.seriesNo=b.TitleNo than Output is displayed as-
    SchedItemNo|     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Than i tried following Query to use the Union based on two conditions:-
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
    a.ScheditemNo in ('2702154')
    Union All
    Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
    from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
    a.ScheditemNo in ('2702154')
    than it display the following result-
    SchedItemNo|     Showname |     EpisodeName
    2702154     |     091706          |     091706
    2702154     |     SUN NIGHTLY NEWS |     SUN NIGHTLY NEWS
    Here also values are not what i want :(
    I want the result to be displayed as using SQL:-
    SchedItemNo |     Showname      |     EpisodeName
    2702154     |     SUN NIGHTLY NEWS |     091706
    Please help me out!
    Thanks in Advance for putting your efforts.Looking forward for your replies.

    SQL> create table scheduleitem
      2  as
      3  select 2702154 scheditemno, 1 titleno, 11 seriesno from dual
      4  /
    Tabel is aangemaakt.
    SQL> create table titles
      2  as
      3  select 1 titleno, '071706' titlename from dual union all
      4  select 11, 'SUN NIGHTLY NEWS' from dual
      5  /
    Tabel is aangemaakt.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      3  a.ScheditemNo in ('2702154')
      4  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    1 rij is geselecteerd.
    SQL> Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      2  from ScheduleItem a,Titles b where a.TitleNo=b.TitleNo and
      3  a.ScheditemNo in ('2702154')
      4  Union All
      5  Select distinct a.SchedItemNo,b.TitleName,b.TitleName as EpisodeName
      6  from ScheduleItem a,Titles b where b.TitleNo=a.SeriesNo and
      7  a.ScheditemNo in ('2702154')
      8  /
                               SCHEDITEMNO TITLENAME        EPISODENAME
                                   2702154 071706           071706
                                   2702154 SUN NIGHTLY NEWS SUN NIGHTLY NEWS
    2 rijen zijn geselecteerd.
    SQL> select a.SchedItemNo "SchedItemNo"
      2       , show.TitleName "Showname"
      3       , episode.TitleName "EpisodeName"
      4    from ScheduleItem a
      5       , Titles episode
      6       , Titles show
      7   where a.TitleNo = episode.TitleNo
      8     and a.SeriesNo = show.TitleNo
      9  /
                               SchedItemNo Showname         EpisodeName
                                   2702154 SUN NIGHTLY NEWS 071706
    1 rij is geselecteerd.Regards,
    Rob.

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

  • Select query for fetching from 3 tables.

    Can we have a single Select query for fetching same fields (kappl,kschl,vkorg,vtweg,spart,kunwe,datbi,knuma,datab,knumh)
    from 3 tables >> KOTE707,KOTE708 and KOTE709 into an internal table for a particular KUNNR?
    Regards,
    Shashank.

    Hi,
    If you have kunnr field in all the 3 tables then it is possible. use inner join as below
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    SELECT c~carrname p~connid f~fldate
           INTO CORRESPONDING FIELDS OF TABLE itab
           FROM ( ( scarr AS c
             INNER JOIN spfli AS p ON p~carrid   = c~carrid
                                  AND p~cityfrom = p_cityfr
                                  AND p~cityto   = p_cityto )
             INNER JOIN sflight AS f ON f~carrid = p~carrid
                                    AND f~connid = p~connid ).
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    <b>Reward Points if this helps,</b>
    Satish

  • Query help in select Distinct on one column.

    CREATE GLOBAL TEMPORARY TABLE Table1 (
    ID1 varchar2(100) ,
    Name1 varchar2(100),
    Name11 varchar2(100)
    insert into Table1 values ('a','n1','h3');
    insert into Table1 values('b','n2','h2');
    insert into Table1 values('a','n3','h1');
    insert into Table1 values('c','n4','h5');
    insert into Table1 values ('c','n5','h4');
    insert into Table1 values('d','n6','h6');
    select * from Table1;
    ID1,NAME1,     NAME11
    a,     n1,     h3
    b,     n2,     h2
    a,     n3,     h1
    c,     n4,     h5
    c,     n5,     h4
    d,     n6,     h6
    I am trying to select distinct ID1 and all values associated with it which is max row.I want to result as -
    ID1,NAME1,     NAME11
    a,     n3,     h1
    b,     n2,     h2
    c,     n5,     h4
    d,     n6,     h6
    Can you please help me to write simple query to get above result.
    Edited by: 871447 on Jul 25, 2011 9:42 AM
    Edited by: 871447 on Jul 25, 2011 9:45 AM

    Hi,
    Do a self-join, to combine the two rows for each value of id1 onto one output row.
    Make it an outer join, in case there is only one row with a vlaue for id1.
    SELECT  l.id1
    ,     l.name1
    ,     NVL ( r.name11
             , l.name11
             )          AS name11
    FROM              table1     l
    LEFT OUTER JOIN     table1     r  ON  l.id1     = r.id1
                              AND l.name1     < r.name1
    ;Edited by: Frank Kulash on Jul 25, 2011 12:57 PM
    Sorry, I mis-read the problem.
    Lee's solution, above, assumes that name1 is unique, as it is in your sample data.
    What output would you want if that's not the case?
    If name1 is not unique, but the combination of (id1, name1) is unique, then you can modify Lee's solution like this:
    SELECT  *
    FROM    table1
    WHERE   (id1, name1) IN (
                        SELECT    id1
                        ,       MAX (name1)
                               FROM          table1
                        GROUP BY  id1
    ;Or, if you can't make any assumptions about uniqueness, you might need something like this:
    WITH     got_r_num     AS
         SELECT  id1, name1, name11
         ,     ROW_NUMBER () OVER ( PARTITION BY  id1
                                   ORDER BY          name1     DESC
                             ,                name11     DESC
                           )      AS r_num
         FROM     table1
    SELECT  id1, name1, name11
    FROM     got_r_num
    WHERE     r_num     = 1
    ;

  • Need of SQL query in selecting distinct values from two tables

    hi,
    I need a query for selecting distinct values from two tables with one condition.
    for eg:
    there are two tables a & b.
    in table a there are values like age,sex,name,empno and in table b valuses are such as age,salary,DOJ,empno.
    here what i need is with the help of empno as unique field,i need to select distinct values from two tables (ie) except age.
    can anybody please help me.
    Thanks in advance,
    Ratheesh

    Not sure what you mean either, but perhaps this will start a dialog:
    SELECT DISTINCT a.empno,
                    a.name,
                    a.sex,
                    b.salary,
                    b.doj
    FROM    a,
            b
    WHERE   a.empno = b.empno;Greg

  • Help! Howto use the join function in a query with select distinct ?

    Hi!
    I have 2 tables. I want to select only 1 painting of each artists.
    select distinct idartist
    from tbl_artworks
    where blah blah blah
    order by rand()
    how does the "join" function work for add: name, lastname, title, image and much more... i try... but i fail...
    tbl_artists
    idartist
    name
    lastname
    1
    Paul
    Gaugain
    2
    Vincent
    Van Gogh
    3
    Pablo
    Picasso
    tbl_artworks
    idartwork
    idartist
    title
    image
    1
    1
    days of gods
    image1.jpg
    2
    2
    sunflower
    image2.jpg
    3
    3
    Dora maar au chat
    image3.jpg
    4
    2
    Sky
    image4.jpg
    5
    3
    La vie
    image5.jpg

    Getting a single random image for each probably requires a combination of sql and cf.  It would take someone smarter than me to do it with sql alone.  I would probably try something like this:
    1.  Run a database query that gets all the images from all the artists.
    2.  Run a Q of Q that gets a distinct list of artist ids.
    3.  Loop through that list and run a Q of Q to get all the images for that artist.
    4.  Still in that loop, use randrange (1 to the recordcount) to select a random record from your Q of Q

  • Select distinct from an infoset query

    Hello
    I need to select distinct / delete duplicate from an infoset query created thru SQ02.
    Please let me to know how this can be done?
    Many thanks in advance!
    regards
    Sanjyot

    Hi,
    You can verywell use infoset query if you are doing following things
    Join using Keyfields to retreive data from tables
    If not using keyfields create index for those table fields  in those fields which will improve in accessing database
    Try to use minimum of tables of small size dont try to join big tables like GLPCA and all.
    Try to load small set of data like a period or month. Dont try for a year or so.
    if your performance is good for aperiod you can go for a year.
    If you are good in function module you can try function module in which you will have the option of specifying no of records to be selected usign package size.
    Hope this helps for you.
    Thanks,
    Arun

  • Select distinct records in query

    If I want to read a table in an infoset, how can I just select distinct entries from the table?
    Is it done at the infoset level or the query level?

    I've actually created the infoset for table VBFA and created a query.
    But I can't limit the output such that for each DO, show only distinct subsequent Invoice.
    eg. DO 123 has 3 items, and this DO 123 has only 1 Invoice 456, then in the output, there will be
    DO    |     Invoice
    123   |     456
    123   |     456
    123   |     456
    It's repeated 3 times because there are 3 items in VBFA for this DO. How can I create the infoset/query so that the output will be 1 entry only, ie
    DO    |     Invoice
    123   |     456
    Thanks

  • Select the Key Figures to be presented in a query before execute the it

    Hi,
    I want to select(through checkbox) the Key Figures to be presented in a query before executing the query. I'm creating BEX queries and web templates (I'm working on BEX 7.0).
    I haven't found clear post about this so if you have implemented something like this please help me and share your solution.
    Kind regards,
    Ana

    Hi,
    If you set a property of your KF as "Hide and can be shown", you will get a filter option for these KFs after executing the report in the navigational block of web report.
    When you click on that filter, you will get the list of KFs, then you can select the desired KFs using check box.
    Regards,
    Yogesh.

  • Select single record per distinct type

    My test table is shown below, I needed to return just ONE invoice for each distinct prov_type
    PROV_TYPE INVOICE
    E 111
    E 222
    E 333
    AL 444
    I could use: SELECT distinct prov_type,
    min(invoice)
    FROM test_table
    Yields (one invoice per prov_type):
    Prov_type Invoice
    E 111
    AL 444
    But to extend this, how would I get the same result when
    there are more than just the 2 columns (prov_type and invoice)?
    Example data (selected from numerous tables):
    PROV_TYPE INVOICE SOME_DATES SCHEDULE
    E 111 JUNE 1 40A
    E 222 JUNE1 7A-C
    E 333 MAY 1 20C
    AL 444 JULY 1 7C-R
    I'm trying to select ONE invoice example of
    each prov_type.
    Is there any way to write something to
    get one record of each type of prov_type?....without having to execute the
    underlying where clause twice (once to get the distinct prov type and min
    invoice, and one to get the rest of the data for the invoice???)? I'm wondering this
    because the underlying where clause to get the above data set could be slow.
    I keep thinking there should be some way to select the above data set, and
    then somehow use a subquery or rownum or count(*) or something else to pick and choose the
    records I want from this set.
    Also, I have something similar to this where I select a bunch of data, and I
    want one record where a type column = R and one record where the same type
    column is NOT R. Same idea.. is there any way to select the "bunch of
    data" one time and manipulate the result set? Or do I have to:
    SELECT a_bunch_of_data
    FROM a_bunch_of_tables
    WHERE a_bunch_of_conditions
    AND the_type = 'R'
    AND rownum < 2
    UNION
    SELECT a_bunch_of_data (AGAIN)
    FROM a_bunch_of_tables (AGAIN)
    WHERE a_bunch_of_conditions (AGAIN)
    AND the_type <> 'R'
    AND rownum < 2

    Using PL/SQL AND/OR Dynamic SQL can simplify this. If your requirement
    is strictly SQL however, and your main goal is not to have to join
    anything else to your view, one (tricky) way would involve the following:
    1. get the data length of each needed column (except the key column) from the table definition.
    2. convert each of these column into character type, left padded to its data length
    3. concatenate these columns, with the target column in the front (e.g. Invoice Number)
    4. Apply the group function on the concatenated string, grouping by the key column.
    5. parse the string back
    This shouldn't be bad if you have to set it up only once!
    Note: for the second problem, you can use the same technique, with:
    GROUP BY DECODE(the_type,'R','R','Not R')
    CREATE TABLE test_table (
    PROV_TYPE VARCHAR2(10),
    INVOICE NUMBER,
    SOME_DATE DATE,
    SCHEDULE VARCHAR2(20),
    some_num_field NUMBER(5,3)
    INSERT INTO test_table VALUES('E',111,TO_DATE('JUN 1','MON DD'),'40A',12.123);
    INSERT INTO test_table VALUES('E',22,TO_DATE('JUN 1','MON DD'),'7A-C',3.04);
    INSERT INTO test_table VALUES('E',333,TO_DATE('MAY 1','MON DD'),'20C',1.4);
    INSERT INTO test_table VALUES('AL',444,TO_DATE('JUL 1','MON DD'),'7C-R',9);
    INSERT INTO test_table VALUES('Z',9,TO_DATE('JUL 1','MON DD'),'7C-R',12.123);
    INSERT INTO test_table VALUES('Z',123,TO_DATE('JUL 1','MON DD'),'7C-R',12.123);
    INSERT INTO test_table VALUES('Z',999,TO_DATE('JUL 1','MON DD'),'7C-R',99.999);
    SELECT
    PROV_TYPE,
    TO_NUMBER(SUBSTR(
    MIN(LPAD(invoice,38) &#0124; &#0124; TO_CHAR(some_date,'YYYYMMDDHH24MISS') &#0124; &#0124;
    LPAD(schedule,20) &#0124; &#0124; LPAD(some_num_field,39)),
    1,38)) invoice,
    TO_DATE(SUBSTR(
    MIN(LPAD(invoice,38) &#0124; &#0124; TO_CHAR(some_date,'YYYYMMDDHH24MISS') &#0124; &#0124;
    LPAD(schedule,20) &#0124; &#0124; LPAD(some_num_field,39)),
    38+1,14),'YYYYMMDDHH24MISS') some_date,
    LTRIM(SUBSTR(
    MIN(LPAD(invoice,38) &#0124; &#0124; TO_CHAR(some_date,'YYYYMMDDHH24MISS') &#0124; &#0124;
    LPAD(schedule,20) &#0124; &#0124; LPAD(some_num_field,39)),
    38+14+1,20)) schedule,
    TO_NUMBER(SUBSTR(
    MIN(LPAD(invoice,38) &#0124; &#0124; TO_CHAR(some_date,'YYYYMMDDHH24MISS') &#0124; &#0124;
    LPAD(schedule,20) &#0124; &#0124; LPAD(some_num_field,39)),
    38+14+20+1,39)) some_num_field
    FROM test_table
    GROUP BY prov_type
    /null

  • Serious performance problem - SELECT DISTINCT x.JDOCLASSX FROM x

    I am noticing a huge performance problem when trying to access a member that
    is lazily loaded:
    MonitorStatus previousStatus = m.getStatus();
    This causes the following query to be executed:
    SELECT DISTINCT MONITORSTATUSX.JDOCLASSX FROM MONITORSTATUSX
    This table has 3 million records and this SQL statement takes 3 minutes to
    execute! Even worse, my app heavily uses threads, so this statement is
    executed in each of the 32 threads. As a result the application stops.
    Is there any way that I can optimize this? And more importantly, can Kodo
    handle a multithreaded app like this with a huge database? I've been having
    a lot of performance problems since I've started doing stress & load
    testing, and I'm thinking Kodo isn't ready for this type of application.
    Thanks,
    Michael

    You can prevent this from happening by explicitly enumerating the valid
    persistent types in a property. See
    http://docs.solarmetric.com/manual.html#com.solarmetric.kodo.PersistentTypes
    for details.
    >
    Inconveniently, this nugget of performance info is not listed in the
    optimization guide. I'll add in an entry for it.This setting did in fact prevent the query from running which fixed the
    problem. It definitely belongs in the optimization guide.
    And more importantly, can Kodo
    handle a multithreaded app like this with a huge database? I've beenhaving
    a lot of performance problems since I've started doing stress & load
    testing, and I'm thinking Kodo isn't ready for this type of application.I'd like to find out more information about details about your issues. We
    do a decent amount of stress / load testing internally, but there are
    always use cases that we don't test. Please send me an email (I'm assuming
    that [email protected] is not really your address) and let's
    figure out some way to do an analysis of what you're seeing.This email is just for posting to usenet, to avoid spam. I'm now running my
    app through stress/load testing so I hope to discover any remaining issues
    before going into production. As of this morning the system seems to be
    performing quite well. Now the biggest performance problem for me is the
    lack of what I think is called "outer join". I know you'll have this in 3.0
    but I'm suprised you don't have this already because not having it really
    affects performance. I already had to code one query by hand with JDBC due
    to this. It was taking 15+ minutes with Kodo and with my JDBC version it
    only takes a few seconds. There are lots of anti-JDO people and performance
    issues like this really give them ammunition. Overall I just have the
    impression that Kodo hasn't been used on many really large scale projects
    with databases that have millions of records.
    Thanks for configuration fix,
    Michael

  • SQL Query to Fetch 500 Rows at once

    Hi,
      Due to performance issue of the SQL query takes lot of time to execute. I tried modifying the code as mentioned below but it is not working to fetch when search is implemented. Actually data is more than 1 Million Records so it takes lot of time to query the data.
    SELECT DISTINCT
    IMV.*,
      nvl(imv.party_name,imv.bill_to_name) "Bill To Name",
      Imv.Ship_To_City "Reseller City",
      Imv.Ship_To_State "Reseller State",
      Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
      Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
      Cl.City "Customer City",
      Cl.State "Customer State",
      EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'COUNTRY') "Customer Country",
      EDB2_GLOBAL.COUNTRY_NAME_THEATER(CL.COUNTRY,'THEATER') "Customer Theater"
    FROM IB_SUPPORT_CONTRACTS_MV IMV,
      customer_products cp,
      customer_locations cl
    WHERE
    UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
    AND CP.LOCATION_ID                     = CL.LOCATION_ID(+)
    AND ROWNUM <= 501
    Please suggest me how to improve the performance of the query.
    Thanks
    Sudhir

    Hi,
    As mentioned already, this condition is really hurting performance:
    UPPER(TRIM(IMV.SERIAL_NUMBER)) = UPPER(TRIM(CP.PRODUCT_SERIAL_NUMBER(+) ) )
    Could you trim and capitalize the serial numbers before storing them?  Do you really need to remember exactly how the serial numbers were entered?  If you really do, then store it in one column, and store UPPER (TRIM (serial_number)) in a different column.  Starting in Oracle 11, this could be a virtual column; in any version (7 or higher), it could be maintained by a trigger.  Failing that, create a function-based index on UPPER (TRIM (serial_number)).

  • SELECT DISTINCT does not work. Why?

    Dear All,
    I wrote the Query below in SAP B1 8.8 and it works fine.
    But, for some strange reason, certain records are duplicated.
    Could anybody explain why?
    I tried to eliminate the duplicates by changing the 1st line of the Query from SELECT to SELECT DISTINCT
    Error Message:
    The ntext data type cannot be selected as DISTINCT because it is not comparable.
    Could you help amend the Query?
    Thanks
    Leon Lai
    SELECT
    T0.[UpdateDate] AS 'Update Dt',
    T0.[TaxDate] AS 'Doc Dt',
    CASE T5.[TransType]
         WHEN '18' THEN 'PU ' + CONVERT(VARCHAR(6), T0.[DocNum])
         WHEN '19' THEN 'PC ' + CONVERT(VARCHAR(6), T0.[DocNum])
    END 'SAP Ref.',
    T1.[ImportLog]     AS 'Ship #',
    T0.[CardCode] + '' AS 'Supplier #',
    T0.[CardName]      AS 'Supplier Name',
    T0.[DocTotal]      AS 'Rs',
    T1.[BlockNum]      AS 'Reqn #',
    T0.[DocNum]        AS 'Doc No',
    T0.[U_SupInv]      AS 'Link'
    FROM klship.[dbo].[OPCH] T0
    INNER JOIN klship.[dbo].[PCH1] T1 ON T0.[DocEntry] = T1.[DocEntry]
    INNER JOIN klship.[dbo].[OJDT] T5 ON T0.[TransID] = T5.[TransID]
    WHERE
    (T0.[UpdateDate] >= '[%2]' AND
    T0.[UpdateDate]  <= '[%3]' AND
    T0.[U_SupInv] IS NULL)
    OR
    (T0.[UpdateDate] >= '[%4]' AND
    T0.[UpdateDate]  <= '[%5]' AND
    T0.[U_SupInv] IS NOT NULL)
    FOR BROWSE
    Note: -  U_SupInv is a UDF used to attach a scanned pdf file to the Supplier's Invoice.

    Dear István Korös,
    Thanks a lot for your answer.
    Your suggestion works!
    I am closing this thread.
    However, I have never met the problem of duplicate records before
    with such straightforward Queries.
    If you could explain to me why such duplicates arose, it would be very
    satisfying.
    Best Regards
    Leon Lai

Maybe you are looking for