Problem with Select Statements

Hi All,
I have a performance problem for my report because of the following statements.
How can i modify the select statements for improving the performance of the report.
DATA : shkzg1h  LIKE bsad-shkzg,
         shkzg1s  LIKE bsad-shkzg,
         shkzg2h  LIKE bsad-shkzg,
         shkzg2s  LIKE bsad-shkzg,
         shkzg1hu LIKE bsad-shkzg,
         shkzg1su LIKE bsad-shkzg,
         shkzg2hu LIKE bsad-shkzg,
         shkzg2su LIKE bsad-shkzg,
         kopbal1s  LIKE bsad-dmbtr,
         kopbal2s  LIKE bsad-dmbtr,
         kopbal1h  LIKE bsad-dmbtr,
         kopbal2h  LIKE bsad-dmbtr,
         kopbal1su  LIKE bsad-dmbtr,
         kopbal2su  LIKE bsad-dmbtr,
         kopbal1hu  LIKE bsad-dmbtr,
         kopbal2hu  LIKE bsad-dmbtr.
*These statements are in LOOP.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg1s , kopbal1s)
      FROM bsid
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'S'
       AND umskz EQ ''
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg1su , kopbal1su)
      FROM bsid
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'S'
       AND umskz IN zspgl
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg1h , kopbal1h)
      FROM bsid
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'H'
       AND umskz EQ ''
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg1hu , kopbal1hu)
      FROM bsid
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'H'
       AND umskz IN zspgl
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg2s , kopbal2s)
      FROM bsad
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'S'
       AND umskz EQ ''
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg2su , kopbal2su)
      FROM bsad
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'S'
       AND umskz IN zspgl
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg2h , kopbal2h)
      FROM bsad
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'H'
       AND umskz EQ ''
     GROUP BY shkzg.
    ENDSELECT.
    SELECT shkzg SUM( dmbtr )
      INTO (shkzg2hu , kopbal2hu)
      FROM bsad
     WHERE bukrs = ibukrs
       AND kunnr = ktab-kunnr
       AND budat < idate-low
       AND shkzg = 'H'
       AND umskz IN zspgl
     GROUP BY shkzg.
    ENDSELECT.

>
Siegfried Boes  wrote:
> Please stop writing answers if you understrand nothing about database SELECTS!
> All above recommendations are pure nonsense!
>
> As always with such questions, you must do an analysis before you ask! The coding itself is perfectly o.k., a SELECT with an aggregate and a GROUP BY can not be changed into a SELECT SINGLE or whatever.
>
> But your SELECTS mustr be supported by indexes!
>
> Please run SQL Trace, and tell us the results:
>
> I see 8 statements, what is the duration and the number of records coming back for each statement?
> Maybe only one statement is slow.
>
> See
> SQL trace:
> /people/siegfried.boes/blog/2007/09/05/the-sql-trace-st05-150-quick-and-easy
>
>
> Siegfried
Nice point there Siegfried. Instead of giving constructive suggestion, people here give a very bad suggestion on using SELECT SINGLE combined with SUM and GROUP BY.
I hope the person already look at your reply before he try using select single and wondering why he has error.
Anyway, the most important thing is how many loop expected for those select statements?
If you have like thousands of loop, you can expect a poor performance.
So, you should also look at how many times the select statement is called and not only performance for each select statement when you're doing SQL trace.
Regards,
Abraham

Similar Messages

  • Problem with Select statement.

    DATA: wa_usr05   TYPE usr05.
    The select statement always gives sy-subrc = 0
    even if there is no entry with parid = 'ZRD'.
    On successful it fills the structure wa_usr05 as
    MANDT     C     3      ACC
    BNAME     C     12      SCL
    PARID     C     20      X
    PARVA     C     18
    but mandt is 310.
    USR05 is a pool table and has mandt field.
            SELECT SINGLE bname
                          parid
                          parva
                FROM usr05
                INTO wa_usr05
                WHERE bname = sy-uname AND
                      parid = 'ZRD'    AND
                      parva = 'x'  OR  parva = 'X'.
    Let me know the reason and solution to the problem.

    SELECT SINGLE * FROM usr05
    INTO wa_usr05
    WHERE bname = sy-uname AND
    parid = 'ZRD' AND
    parva = <b>'X'</b> .
    Use single * as u have defined the wa+usr05 as usr05.
    Else.
    DATA: i_usr05 TYPE STANDARD TABLE of usr05.
    SELECT * FROM USR05
             INTO TABLE usr05
             WHERE bname = sy-uname AND
             parid = 'ZRD' AND
            parva = <b>'X'</b> .
    Then loop at itab and write data.
    Hope this solves ur query.
    Reward points if this helps.
    Message was edited by:
            Judith Jessie Selvi

  • Problem with SELECT statement. What is wrong with it?

    Why is this query....
    <cfquery datasource="manna_premier" name="kit_report">
    SELECT Orders.ID,
           SaleDate,
           Orders.UserID,
        Distributor,
        DealerID,
        Variable,
        TerritoryManager,
        US_Dealers.ID,
           DealerName,
        DealerAddress,
        DealerCity,
        DealerState,
        DealerZIPCode,
        (SELECT SUM(Quantity)
         FROM ProductOrders PO
         WHERE PO.OrderID = Orders.ID) as totalProducts,    
    FROM Orders, US_Dealers
    WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
    </cfquery>
    giving me this error message...
    Error Executing Database Query.
    [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
    The error occurred in D:\Inetpub\mannapremier\kit_report2.cfm: line 20
    18 :              WHERE PO.OrderID = Orders.ID) as totalProducts,        
    19 : FROM Orders, US_Dealers
    20 : WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN #CreateODBCDate(FORM.Start)# AND #CreateODBCDate(FORM.End)# AND Variable = '#Variable#'
    21 : </cfquery>
    22 :
    SQLSTATE
      42000
    SQL
       SELECT Orders.ID, SaleDate, Orders.UserID, Distributor, DealerID, Variable, TerritoryManager, US_Dealers.ID, DealerName, DealerAddress, DealerCity, DealerState, DealerZIPCode, (SELECT SUM(Quantity) FROM ProductOrders PO WHERE PO.OrderID = Orders.ID) as totalProducts, FROM Orders, US_Dealers WHERE US_Dealers.ID = DealerID AND SaleDate BETWEEN {d '2009-10-01'} AND {d '2009-10-31'} AND Variable = 'Chick Days pre-book'
    VENDORERRORCODE
      -3504
    DATASOURCE
      manna_premier
    Resources:
    I copied it from a different template where it works without error...
    <cfquery name="qZVPData" datasource="manna_premier">
    SELECT UserID,
           TMName,
        UserZone,
              (SELECT COUNT(*)
               FROM Sales_Calls
               WHERE Sales_Calls.UserID = u.UserID) as totalCalls,
        (SELECT COUNT(*)
         FROM Orders
         WHERE Orders.UserID = u.UserID) as totalOrders,
        (SELECT SUM(Quantity)
         FROM ProductOrders PO
         WHERE PO.UserID = u.UserID AND PO.NewExisting = 1) as newItems,
        (SELECT SUM(NewExisting)
         FROM  ProductOrders PO_
         WHERE PO_.UserID = u.UserID) as totalNew,
        SUM(totalOrders)/(totalCalls) AS closePerc
    FROM Users u
    WHERE UserZone = 'Central'
    GROUP BY UserZone, UserID, TMName
    </cfquery>
    What is the problem?

    It's hard to say: what's your request timeout set to?
    700-odd records is not much of a fetch for a decent DB, and I would not expect that to case the problem.  But then you're using Access which doesn't fit the description of "decent DB" (or "fit for purpose" or "intended for purpose"), so I guess all bets are off one that one.  If this query is slow when ONE request is asking for it, what is going to happen when it goes live and multiple requests are asking for it, along with all the other queries your site will want to run?  Access is not designed for this.  It will really struggle, and cause your site to run like a dog.  One that died serveral weeks ago.
    What else is on the template?  I presume you're doing something with the query once you fetch it, so could it be that code that's running slowly?  Have you taken any steps to isolate which part of the code is taking so long?
    How does the query perform if you take the subquery out of the select line?  Is there any other way of getting that data?  What subquery will be running once for every row of the result set... not very nice.
    Adam

  • Problem with select statement using Ranges

    Hi Guys,
                   I have used Ranges and used a select statement for selecting those ranges but I am facing a problem.
    RANGES: r_doctyp for EDIDC-DOCTYP.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'DEBMAS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'MATMAS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'PRICAT'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'ORDERS'.
    append r_doctyp.
    r_doctyp-sign = 'I'.
    r_doctyp-option = 'EQ'.
    r_doctyp-low  = 'INVOIC'.
    append r_doctyp.
    Select DOCNUM                                " IDoc number
           DOCTYP                                " IDoc Type
                 from  EDIDC into table IT_ZEDIDC
                 where CREDAT EQ s_credat-low
                 and   DOCTYP EQ r_doctyp        " IDOC Types
                 and   DIRECT EQ '1'.
    Here my select statement is only taking INVOIC.
    But my statement should take any document type.
    Thanks,
    Prasad.

    Hi...,
    Your following select statement is correct.
    Select DOCNUM                                " IDoc number
                DOCTYP                                " IDoc Type
                from  EDIDC into table IT_ZEDIDC
                where CREDAT IN s_credat
                and   DOCTYP IN r_doctyp        " IDOC Types
                and   DIRECT EQ '1'.
    Why you are not getting result..
    1. structure of the IT_ZEDIDC is having two fields DOCNUM , DOCTYP  with same data lengths. If not it should be...
    2. Order in the database table is must be similer to the order you maintained in the select statement.
    3. As you are hard coding the input ranges make sure about every letter.
    4. take a look at other where condition fields too.
    5. check the table of the ranges in debugging mode.
    6. why can't you declare separate work area and table for ranges...?
      like .... data: r_tab type range of <field>
                 data: wa_tab like line of r_tab.
    7. Use clear work area statement after the append statment.
    --Naveen Inuganti.

  • Problems with select statement

    Hi,
    For some reason I cannot find the solution for the following problem.
    I have an internal table.
    Now I like to make an select over a database table, while only rows should be selected, where the key field occurs in the internal table and in case of  identical key field only the row with the lowest value in another column is selcted.
    Example:
    - internal table:
    col1  col2  col3
    1     A     AA
    2     B     AA
    3     A     AC
    -database table:
    col1  col2  col3
    1     001   CD
    1     002   CF
    1     003   CG
    2     001   CD
    2     002   CF
    2     003   CG
    3     002   CF
    3     003   CG
    4     001   CD
    4     002   CF
    4     003   CG
    - the selected database entries should be
    1     001   CD
    2     001   CD
    3     002   CF
    explication:
    - entries with 4 in the first column do not occur in the internal table, so they do not appear in the selection
    - in case of more than one entry in the database table only the one with the lowest value in column two will be selected
    If you have any idea how this could be solved, I would really appreciate you help.
    regards
    Torsten

    Hi,
    1) u have to select based on internal table 1
    2) u have to filter the internal table 2 for minimum value.
    select col1 col2 col3
    from <any table>
    into table <Internal_table_final>
    for all entries in <Internal_table_1>
    where col1 = Internal_table_1-col1.
    sort Internal_table_final by col1 col2.
    loop at Internal_table_final.
       at new col1.
          continue.
       endat.   
       delete Internal_table_final.
    endloop.
    <b>try this</b>
    Regards
    <b>Mark Helpful Answers</b>
    Message was edited by: Manoj Gupta

  • Problem with READ Statement in the field routine of the Transformation

    Hi,
    I have problem with read statement with binary search in the field routine of the transformation.
    read statement is working well when i was checked in the debugging mode, it's not working properly for the bulk load in the background. below are the steps i have implemented in my requirement.
    1. I selected the record from the lookuo DSO into one internal table for all entried in source_packeage.
    2.i have read same internal table in the field routine for each source_package entry and i am setting the flag for that field .
    Code in the start routine
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
         and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp <> 3.
    delete it_zcam where end_dt initial.
    sort it_zcam by surce accno.
    endif.
    field routine code:
    read table it_zcam with key source = source_package-source
                                                 accno  = source_package-accno
                                                 binary search
                                                 transportin no fields.
    if sy-subrc = 0.
    RESULT  = 'Y'.
    else.
    RESULT = 'N'.
    endif.
    this piece of code exist in the other model there its working fine.when comes to my code it's not working properly, but when i debug the transformation it's working fine for those accno.
    the problem is when i do full load the code is not working properly and populating the wrong value in the RESULT field.
    this field i am using in the report filter.
    please let me know if anybody has the soluton or reason for this strage behaviour.
    thanks,
    Rahim.

    i suppose the below is not the actual code. active table of dso would be /bic/azcam_o1100...
    1. is the key of zcam_o11 source and accno ?
    2. you need to get the sortout of if endif (see code below)
    select source accno end_dt acctp from zcam_o11
    into table it_zcam
    for all entries in source_package
    where source = source_package-source
    and accno = source_package-accno.
    if sy-subrc = 0.
    delete it_zcam where acctp 3.
    delete it_zcam where end_dt initial.
    endif.
    sort it_zcam by surce accno.
    field routine code:
    read table it_zcam with key source = source_package-source
    accno = source_package-accno
    binary search
    transportin no fields.
    if sy-subrc = 0.
    RESULT = 'Y'.
    else.
    RESULT = 'N'.
    endif.

  • Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination

    Problem with "SELECT...FOR UPDATE OF..." and "POST command" combination
    Problem in committing transactions in Multiple Forms (Oracle Forms) with POST built-in command:
    Consider that the following statements are written in WHEN-WINDOW-CLOSED trigger of a called form.
    Statements in called form (Form name: FORM_CHILD):
    go_block('display_block') ;
    do_key('execute_query') ;
    -- Data from table_b will be populated in this block, based on the value of COLUMN_1 obtained
    -- from TABLE_A.
    -- Example: If the value of COLUMN_1 is 10, then all the matching records from TABLE_B, which
    -- are inserted with value 10 in TABLE_B.COLUMN_1 will be fetched and shown here.
    if user_choice = 'YES' then
    commit ;
    else
    rollback ;
    end if ;
    Statements in calling forms:
    There are two calling forms having following statements and it is going to call the above said called form.
    CALLING FORM 1
    Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...; Statements in KEY-COMMIT trigger:
    post;
    call_form(form_child, no_activate) ;
    CALLING FORM 2:
    Statements in ON-INSERT trigger:
    select column_1
    from table_a
    for update of column_1
    where column_2 = 'X' ;
    update table_a
    set column_1 = column_1 + 1
    where column_2 = 'X' ;
    insert into table_b ...;
    insert into table_b ...;
    insert into table_b ...;
    Our understanding:
    Assume that both the forms are running from two different machines/instances, issuing commit at the same time. In this case, forms will start executing the statements written in ON-INSERT trigger, the moment POST command is executed. Though the commit is issued at the same time, according to oracle, only one of the request will be taken for processing first. Assume that calling form 1 is getting processed first.
    So, it fetches the value available in COLUMN_1 of TABLE_A and locks the row from further select, update, etc. as SELECT...FOR UPDATE command is used (note that NOWAIT is not given, hence the lock will be released only when COMMIT or ROLLBACK happens) and proceed executing further INSERT statements. Because of the lock provided by the SELECT...FOR UPDATE command, the statements in calling form 2 will wait for the resource.
    After executing the INSERT statements, the FORM_CHILD is called. The rows inserted in to TABLE_A will be queried and shown. The database changes will be committed when user closes the window (as COMMIT is issued in its WHEN-WINDOW-CLOSED trigger). Then the SELECT...FOR UPDATE lock will be released and calling form 2's statements will be executed.
    Actual happenings or Mis-behavior:
    Calling form 2 starts executing INSERT statements instead of waiting for SELECT...FOR UPDATE lock. Also, the value selected from TABLE_A.COLUMN_1 is same in both the calling forms, which is wrong.
    The rows inserted into TABLE_B are having similar COLUMN_1 values in calling form 2 and they are fetched and shown in the called form FORM_CHILD.
    Note that in calling form 2 also POST only is issued, but the changes posted there are accessible in calling form 1 also, which is wrong.
    Kindly suggest us as to how to fix above problem. It will be much use, if you can send us the information regarding the behavior of Oracle Forms POST built-in also.
    Our mail ID: [email protected]
    Thanks a lot in advance.

    You have several problems:
    1. On-Insert will ONLY run if you have created a new record in a base-table block. If you haven't done that, then the POST command will not cause it to run.
    2. Select for update without a "no wait" will lock records for the first form, but when the second form tries this, it will hit the ORA-00054 exception, and will NOT wait. The only way you could make it wait is to issue an UPDATE sql command, which is not such a good way to go.
    All POST does is issues SQL insert or update commands for any changes the user has made to records in a form's base-table blocks, without following with a Commit command.
    Also understand that Commit is the same as Commit_Form, and Rollback is the same as Clear_Form. You should read up on these in the Forms help topics.

  • Problem with:  select 'c' as X from dual

    Problem with 'select 'c' as X from dual'
    I get 2 different results when I execute the above with SQLPlus (or java) depending on the instance I am connected to. For one instance the result is a single character and for the other the character is padded with blanks to 32 chars in the SQLPlus window (and java). Does anyone know what database setting causes this to happen? Is it a version issue ?
    Test #1: Oracle 9.2.0.6 - SQLPlus result is padded with blanks
    SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 10 09:27:58 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.6.0 - Production
    SQL> select 'c' as X from dual;
    X
    c
    SQL>
    Test #2 Oracle 9.2.0.1 SQLPlus result is a single character.
    SQL*Plus: Release 9.2.0.1.0 - Production on Mon Dec 10 09:29:27 2007
    Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.1.0 - Production
    SQL> select 'c' as X from dual;
    X
    c
    SQL>

    Using 9.2.0.6 On AIX 5.2 I get the single byte result:
    UT1 > select 'c' as X from dual;
    X
    c
    If the databases are on different Oracle Homes you may want to check the sqlplus global logon files for any set commands.
    If you executed the two sql statements from different OS directories you may also want to check your sqlpath for sqlplus .logon files.
    Try issueing clear columns and repeating the statement. Are the results the same?
    HTH -- Mark D Powell --

  • Problem with selecting text in Adobe Reader XI

    Hi all, I am encountering a problem with Adobe Reader XI and it is very strange I could not find an alike issue on the internet so I guess I have to submit a question with it.
    So here it is, I am using Adobe Reader XI Version 11.0.2, operating system: Windows 7. I do not know it starts from when but it has the problem with selecting text - to be copied in pdf documents. I ensure that the documents are not scanned documents but word-based documents (or whatever you call it, sorry I cannot think of a proper name for it).
    Normally, you will select the text/paragraph you want to copy and the text/paragraph will be highlighted, but the problem in this case that I cannot select the text/paragraph, the blinking pointer (| <-- blinking pointer) will just stays at the same location so I cannot select/highlight anything to be copied. It happens oftenly, not all the time but 90%.
    This is very annoying as my work involves very much with copying text from pdf documents, I have to close the pdf file and then open it again so I can select the text but then after the first copying or second (if I am lucky), the problem happens again. For a few text I have to type it myself, for a paragraph I have to close all opening pdf documents and open again so I could select the paragraph to copy. I ran out of my patience for this, it causes trouble and extra time for me just to copying those texts from pdf documents. Does this problem happen to anyone and do you have a solution for this? I would much appreciate if you could help me out, thank you!

    Yeah,  I totally agree, this is very strange. I have always been using Adobe Reader but this problem only occurred ~three months ago. It must be that some software newly installed I think. But I have no idea.
    About your additional question, after selecting the texts and Ctrl + C, the texts are copied and nothing strange happens. It's just that right after I managed to copy the texts, it takes me a while to be able to select the texts again. For your information, I just tested to select the texts and then pressed Ctrl, the problem happened. And then I tried pressing C and then others letters, it all led to the problem.
    I guess I have to stick with left-clicked + Copy until I/someone figure the source of this problem. Thanks a lot for your help!

  • Problems with "Select Distinct" Statement

    Hi... I've a little problem with my SQL Statement...
    I've a Table in a DataBase with Solds of the Month... the fields are: vta_fecha, vta_prod, vta_total, vta_mesa.
    I've to Select only the distincts fields of vta_prod... selected by vta_fecha and vta_mesa...
    My code is like this:         try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                conec = DriverManager.getConnection("jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=C:/POOL/Data/BaseDat.MDB");
                state = conec.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);try{
                rec = state.executeQuery("Select DISTINCT vta_prod, vta_fecha, vta_mesa from Ventas where vta_fecha = #" + Fecha_q + "# And vta_mesa = 0");           
                rec.first();
                int x = 0;
                while (rec.isAfterLast()==false){
                    x++;
                    rec.next();
                rec.first();
                if (x > 0){
                    Productos = new String[x];
                    Total_Vta = new int[x];
                    Cant_Prod = new int[x];
                    x = 0;
                    while (rec.isAfterLast() == false){
                        Productos[x] = rec.getString("vta_prod");
                        rec.next();
                        x++;
                else{
                    Productos = new String[0];
                    Total_Vta = new int[0];
                    Cant_Prod = new int[0];
            }catch(Exception e){JOptionPane.showMessageDialog(null,e.getMessage());}Now, in the Table I have only 3 diferents vta_prod, but this Statement returns 9 Rows... and I don't know why...
    Please help me...
    Regards...

    I don�t have a complete picture because I don�t know what values you are passing in the select and I don�t know your column types but this is what I think is happening from what you have shared.
    You may have misunderstood what the DISTINCT keyword does.
    The DISTINCT keyword applies to the full set of columns in the select (not just the first column). So in your case it would be equivalent to:
    SELECT vta_prod, vta_fecha, vta_mesa
    FROM Ventas
    WHERE ...
    GROUP BY by vta_prod, vta_fecha, vta_mesa
    So, it doesn't matter that you only have 3 distinct vta_prod values if you have multiple values being returned in the other columns. The vta_mesa column can only a return a single value as �0�. That leaves the vta_fecha column which is probably a date/time column and is probably the column that is returning the three other distinct values (one date with three distinct times).
    (3 vta_prod) x (3 vta_fecha) x (1 vta_mesa) or 3x3x1 = 9 rows
    So find a way to strip the time from vta_fecha in your select statement and your SQL should return the results you expect. I�m not an Access expect but I think I remember you can use something like the �Convert� or �DatePart� functions to make that happen (check your documentation to be sure)..
    A couple of asides;
    1) You should use a PreparedStatement and rarely if ever use Statement.
    2) You should start Java variable names with lower case.

  • Problem with select....where IN statement

    Hi,
    i have the following select-statement in my z-abap:
      DATA: s_kostl    TYPE RANGE OF cosp-objnr,
      DATA: s_kstar    TYPE RANGE OF kstar,
      SELECT (lv_feldname) INTO lv_betrag
                      FROM coss WHERE lednr = '00' AND
                                 objnr IN s_kostl AND
                                 gjahr = gjahr AND
                                 kstar IN s_kstar AND
                                 wrttp = '04' AND
                                 versn = '000'.
    now i get a dump, because s_kostl and/or s_kstar contains about 11.000 entries (DBIF_RSQL_INVALID_RSQL).
    how can avoid this ? or how i have to 'rewrite' my SQL statment that the ranges-tabs s_kostl AND s_kstar can be processed
    correctly ?
    br, Martin

    Hello.
    I guess that the problem is not the limit or ranges, it is on the select statement. check it
    It should be select single
    yours:
    {code}
    SELECT (lv_feldname) INTO lv_betrag
                      FROM coss WHERE lednr = '00' AND
                                 objnr IN s_kostl AND
                                 gjahr = gjahr AND
                                 kstar IN s_kstar AND
                                 wrttp = '04' AND
                                 versn = '000'.
    {code}
    correct:
    {code}
    SELECT SINGLE (lv_feldname) INTO lv_betrag
                      FROM coss WHERE lednr = '00' AND
                                 objnr IN s_kostl AND
                                 gjahr = gjahr AND
                                 kstar IN s_kstar AND
                                 wrttp = '04' AND
                                 versn = '000'.
    {code}
    Try doing that change. Also, check frist without using LV_feldname, use the name of the field that u want to select, once u get the correct result change it back.
    Regards
    Miguel

  • Problem with PIVOT statement and ORA-56901

    Hi,
    I am having a problem with PIVOT in Oracle.
    I have a view in an oracle 11g database
    that returns me data in the format:- (... indicates left out text)
    DefinitionID ... AttributeValue FieldID
    ============ ============== =======
    ... 3000 X30a9...
    ... JohnN X4674...
    I am then trying to use a PIVOT statement to hopefully give me data
    in the format
    COLUMN1 COLUMN2
    ======= =======
    JohnN 3000
    The PIVOT statement I am trying is
    SELECT X4674... AS Column1,
    X30A9... AS COLUMN2
    FROM (SELECT instanceid, definitionid, attributevalue, FIELDID
    FROM PI_ENTITY_INSTANCE_VIEW) up PIVOT (MAX(ATTRIBUTEVALUE)
    FOR FIELDID IN (X4674...,X30A9... ) )
    where definitionid = hextoraw('7353C67A56C74B5A8234CD16064399E8')
    I have used a very similar VIEW and PIVOT statement for sql server
    (with necessary changes for Oracle applied) and the
    data returns in SQL Server as expected.
    Unfortunately I am getting the Oracle error
    ORA-56901: non-constant expression is not allowed for pivot|unpivot values
    Is there anyway to get a PIVOT working on Oracle where I use the
    fieldid's like I do above or is there some other way to supply the vales to the
    IN clause to overcome this error?
    Thank you for any help you can provide
    John Nugent

    Hi, John,
    Welcome to the forum!
    X4674, X30A9 and os on are the literal values that you're looking for, right?
    In Oracle, string literals need to be enclosed in single-quotes, like this:
    FOR FIELDID IN ('X4674', 'X30A9') You might find it more convenient to assign column aliases in the PIVOT clause, like this:
    PIVOT   (     MAX (attributevalue)
         FOR     fieldid       IN ( 'X4674'     AS column1
                        , 'X30A9'     AS column2
         ) Remember that anything inside quotes is case-sensitive, so 'X30A9' is not equal to 'X30a9'. Use UPPER (or LOWER) to do case-insensitive string comparisons.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can use commonly available tables (such as those in the scott or hr schemas) to show your problem, then you don't have to post any sample data; just the results and explanation.
    Always say which version of Oracle you're using. You did say you were using Oracle 11g, but there's no 11f or 11h, and sometimes the difference between, say 11.1 and 11.2 can be significant. Why not say exactly what you're using, e.g. 11.1.0.7.0?
    You'll get better answers faster if you always supply this information whenever you post a question.
    Edited by: Frank Kulash on Sep 22, 2011 2:09 PM
    Added allliterative alias alternative
    Edited by: Frank Kulash on Sep 22, 2011 4:04 PM

  • Performance problem with selecting records from BSEG and KONV

    Hi,
    I am having performance problem while  selecting records from BSEG and KONV table. As these two tables have large amount of data , they are taking lot of time . Can anyone help me in improving the performance . Thanks in advance .
    Regards,
    Prashant

    Hi,
    Some steps to improve performance
    SOME STEPS USED TO IMPROVE UR PERFORMANCE:
    1. Avoid using SELECT...ENDSELECT... construct and use SELECT ... INTO TABLE.
    2. Use WHERE clause in your SELECT statement to restrict the volume of data retrieved.
    3. Design your Query to Use as much index fields as possible from left to right in your WHERE statement
    4. Use FOR ALL ENTRIES in your SELECT statement to retrieve the matching records at one shot.
    5. Avoid using nested SELECT statement SELECT within LOOPs.
    6. Avoid using INTO CORRESPONDING FIELDS OF TABLE. Instead use INTO TABLE.
    7. Avoid using SELECT * and Select only the required fields from the table.
    8. Avoid nested loops when working with large internal tables.
    9. Use assign instead of into in LOOPs for table types with large work areas
    10. When in doubt call transaction SE30 and use the examples and check your code
    11. Whenever using READ TABLE use BINARY SEARCH addition to speed up the search. Be sure to sort the internal table before binary search. This is a general thumb rule but typically if you are sure that the data in internal table is less than 200 entries you need not do SORT and use BINARY SEARCH since this is an overhead in performance.
    12. Use "CHECK" instead of IF/ENDIF whenever possible.
    13. Use "CASE" instead of IF/ENDIF whenever possible.
    14. Use "MOVE" with individual variable/field moves instead of "MOVE-
    CORRESPONDING" creates more coding but is more effcient.

  • Emergency: problem with update statement!

    hello guys, i have a very serious problem with an update statement in pl/sql.
    i had an application written in sybase, where i had the following update statement:
    update mis_dik_adeia
    set trexon_etos_days = days_per_year
    from mis_dik_adeia, mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    and mis_dik_adeia.adeia_id between :aapo and :aews
    and mis_dik_adeia.employee_id = :erg
    and mis_dik_adeia.etos = :etos
    and mis_plafon_adeivn.years_yphr = ( select max( a.years_yphr ) from mis_plafon_adeivn a where a.adeia_id = mis_plafon_adeivn.adeia_id and a.years_yphr <= :eth ) using sqlca;
    This is working properly in sybase. When i copied this code in pl/sql it displayed me error and it's impossible to work. Then i thought to make a nested select statement like this:
    update mis_dik_adeia
    set trexon_etos_days = (select days_per_year
    from mis_dik_adeia, mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    and mis_dik_adeia.adeia_id between aapo and aews
    and mis_dik_adeia.employee_id = erg
    and mis_dik_adeia.etos = etos1
    and mis_plafon_adeivn.years_yphr = (
    select max( a.years_yphr )
    from mis_plafon_adeivn a
    where a.adeia_id = mis_plafon_adeivn.adeia_id
    and a.years_yphr <= eth )
    but as you can understand, it is working, but it doesn't produce the same results as the update statement in Sybase!
    It is very important for me to solve this problem , which is a very big trouble for me for a long time.
    Please if anyone can help me i would appreciate it a lot!
    Regards ,
    Bill...

    Bill,
    folowing the logic of your original query by Sybase
    (it's embedded SQL in Power Builder, isn't it ?):
    update mis_dik_adeia
    set trexon_etos_days = (select days_per_year
    from mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    and mis_plafon_adeivn.years_yphr = (
    select max( a.years_yphr )
    from mis_plafon_adeivn a
    where a.adeia_id = mis_plafon_adeivn.adeia_id
    and a.years_yphr <= eth )
    where
    mis_dik_adeia.adeia_id between aapo and aews
    and mis_dik_adeia.employee_id = erg
    and mis_dik_adeia.etos = etos1
    and
    exists (select 1
    from mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    and mis_plafon_adeivn.years_yphr = (
    select max( a.years_yphr )
    from mis_plafon_adeivn a
    where a.adeia_id = mis_plafon_adeivn.adeia_id
    and a.years_yphr <= eth )
    In 9i you can also try the following:
    megre into mis_dik_adeia
    using (
    select
    days_per_year,
    mis_dik_adeia.rowid rid
    from mis_dik_adeia, mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    mis_dik_adeia.adeia_id between aapo and aews
    and mis_dik_adeia.employee_id = erg
    and mis_dik_adeia.etos = etos1
    and mis_plafon_adeivn.years_yphr =
    (select max( a.years_yphr )
    from mis_plafon_adeivn a
    where a.adeia_id = mis_plafon_adeivn.adeia_id
    and a.years_yphr <= eth)
    ) src
    on (mis_dik_adeia.rowid = src.rid)
    when matched then
    update set mis_dik_adeia.trexon_etos_days = src.days_per_year
    when not matched then
    insert (mis_dik_adeia.adeia_id) values(0);
    In 10G it can be easily:
    megre into mis_dik_adeia
    using (
    select
    days_per_year,
    mis_dik_adeia.rowid rid
    from mis_dik_adeia, mis_plafon_adeivn
    where mis_dik_adeia.adeia_id = mis_plafon_adeivn.adeia_id
    mis_dik_adeia.adeia_id between aapo and aews
    and mis_dik_adeia.employee_id = erg
    and mis_dik_adeia.etos = etos1
    and mis_plafon_adeivn.years_yphr =
    (select max( a.years_yphr )
    from mis_plafon_adeivn a
    where a.adeia_id = mis_plafon_adeivn.adeia_id
    and a.years_yphr <= eth)
    ) src
    on (mis_dik_adeia.rowid = src.rid)
    when matched then
    update set mis_dik_adeia.trexon_etos_days = src.days_per_year;
    I have to notice I didn't check it carefully, so I can miss...
    Rgds.
    Corrected a mistake in the table name
    Message was edited by:
    dnikiforov

  • Problem with MERGE statement

    Hi All,
    We are encountering a strange problem with the merge command.
    The following statement works :-
    merge into ATTRIBUTE_GROUP@US_PRODUCT_UAT a
    using
         select
              a1.group_id,
              a1.NAME,
              a1.CREATE_DATE,
              a1.MODIFY_DATE
         from
              ATTRIBUTE_GROUP_LOG a1,
              product_push_wrk a2
         where
              a2.column_id = a1.group_id and
              a2.modify_date = a1.modify_date ) b
    on ( a.group_id = b.group_id)
    when matched then
         update set
              a.NAME = b.NAME,
              a.CREATE_DATE = b.CREATE_DATE,
              a.MODIFY_DATE = b.MODIFY_DATE
    when not matched then
         insert
              a.group_id,
              a.NAME,
              a.CREATE_DATE,
              a.MODIFY_DATE
         values
              b.group_id,
              b.NAME,
              b.CREATE_DATE,
              b.MODIFY_DATE
    However when we change the order of the columns in the select query as follows the an error occurs : -
    merge into ATTRIBUTE_GROUP@US_PRODUCT_UAT a
    using
         select
              a1.NAME,
              a1.group_id,
              a1.CREATE_DATE,
              a1.MODIFY_DATE
         from
              ATTRIBUTE_GROUP_LOG a1,
              product_push_wrk a2
         where
              a2.column_id = a1.group_id and
              a2.modify_date = a1.modify_date ) b
    on ( a.group_id = b.group_id)
    when matched then
         update set
              a.NAME = b.NAME,
              a.CREATE_DATE = b.CREATE_DATE,
              a.MODIFY_DATE = b.MODIFY_DATE
    when not matched then
         insert
              a.group_id,
              a.NAME,
              a.CREATE_DATE,
              a.MODIFY_DATE
         values
              b.group_id,
              b.NAME,
              b.CREATE_DATE,
              b.MODIFY_DATE
    ERROR at line 15:
    ORA-00904: "B"."GROUP_ID": invalid identifier
    SQL> l 15
    15* on ( a.group_id = b.group_id)
    The structure of the attribute_log table is as follows :-
    SQL> desc ATTRIBUTE_GROUP
    Name Null? Type
    GROUP_ID NOT NULL NUMBER
    NAME NOT NULL VARCHAR2(96)
    CREATE_DATE NOT NULL DATE
    MODIFY_DATE NOT NULL DATE
    Any pointers to the cause of this error will be highly appreciated.
    Thanks and Regards,
    Suman

    The table structures are as follows :-
    04:17:17 SQL> desc product_push_wrk
    Name Null? Type
    COLUMN_ID NOT NULL NUMBER
    TYPE NOT NULL VARCHAR2(10)
    PARENT_COLUMN_ID NUMBER
    LEVEL_NO NUMBER
    MODIFY_DATE NOT NULL DATE
    04:17:25 SQL> desc ATTRIBUTE_GROUP_LOG
    Name Null? Type
    GROUP_ID NOT NULL NUMBER
    NAME NOT NULL VARCHAR2(96)
    CREATE_DATE DATE
    MODIFY_DATE DATE
    04:18:02 SQL> desc ATTRIBUTE_GROUP
    Name Null? Type
    GROUP_ID NOT NULL NUMBER
    NAME NOT NULL VARCHAR2(96)
    CREATE_DATE DATE
    MODIFY_DATE DATE

Maybe you are looking for

  • HT1657 Why doesn't my rental movie download completely? iPad

    I am trying to download a rental movie so I can watch later, hopefully during my flight. Movie almost completes downloading then stops and starts over.

  • Reg CIC WEB Client

    Hi to every budy, I am new to CRM. I want to learn CRM IC Web Client i am having CRM IDES. For doing the CRM IC Web client what r the softwares we requred and can any one have deatalied steps regarding installation of IC Web client. pls tell process

  • [DeployDecisionServices] Failed at "Could not get DeploymentManager"

    Hi Everyone, I've a small deployment issues which you guys might be able to help me with. I've created a simple business rule using Oracle Business Rule in my embedded OC4J instance and I've also created a BPEL project that consumes this Oracle Busin

  • Error 1327.invalid drive: C:\ when trying to install

    My computer crashed a while back and when I set up the new drive, the new root drive is "G:\"  instead of "C:\".  how can I get palm software to setup on "G"? if that is what I need to do. Post relates to: Palm m500

  • Recompile Applet, see old vers in browser

    I am developing an Applet. I make changes to the code. I recompile it successfully. I load its' associated HTML file into my browser (IE6). Instead of seeing the new version, I see the old. I have clicked on 'Tools', then 'Internet Options...', then