EarlyWatch - Expensive SQL Statements help

Hi all,
i need to analyze an EWA report and i don't know how exactly can i identify an "expensive SQL statement".
The report says:
During this session, the following expensive SQL statements were identified as causing a database load of at least 1%.
The corresponding stored procedure names are referenced in the table below.
And in the table with stored procedure names, a row looks like this:
ID     Stored Procedure Name
1     ##Y4DCWWES7EHY100000053960000254832042037
What does it mean and how can i identify the name of program and the exact statement (probably select) that is causing this problem?
Thank you,
Ondrej

Hi Ondrej,
you're running on SQL Server. SAP creates stored procedures for each and every statement run against the database. The name you get seems to be a temporary stored procedure which (if I'm not wrong) is marked by the two # characters at the beginning. You may be still find it in the stored procedures of your system.
Open the Enterprise Manager and open your database, then the stored procedure link (you should run the Enterprise Manager on the server or on a PC with enough RAM). The search for the procedure and double click on it. I think that should show you the SQL statement. There should also the report name is a comment.
Regards
Ralph

Similar Messages

  • Expensive SQL statements in GTS

    Hi,
    Recently EWA has been run for the GTS system.There are expensive SQL statements that were causing the Performance issue.It would be a great help if anyone can advise on how these expensive SQL statments can be fine tuned. As all these statements were in standard SAP programs is it that we had the only option to create secondary indices ?
    Moderator message - Please respect the 5,000 character maximum when posting. Post only the relevant portions of code
    Please see Please Read before Posting in the Performance and Tuning Forum before posting
    Any suggestion on performance improvement is appreciated.
    Thanks in advance!!
    Regards,
    Sharon.
    Edited by: Rob Burbank on Nov 15, 2010 9:08 AM

    please ask specific questions.
    Otherwise there are services by SAP, either training or support, but they are not for free.
    Siegfried

  • Expensive SQL statements & no proper indexing INCLUDE LPSSTU03-PSST FuncGrp

    Hi there forum
    During a recent upgrade we have implemented EhP4 with relevant Support Packs.
    Our Early Watch Report nows highlights INCLUDE LPSSTU03 in Function Module Group PSST as having expensive SQL statements along with improper indexing.
    Although I have seached through OSS and Forums I can find nothing of help.
    Is there an EXPERT out there who can help because SAP tells me that is the way it works!
    Thanks.
    Carl Cavendish-Davies

    Herewith the latest results from the Early Watch report on this issue:
    Object Type     Total Executions Disk Reads     Elapsed Time     Buffer Gets     Records Processed
    TABLE     242481         1873373     12035981     36237218     34390383
    SELECT
    "MANDT" , "OBJNR" , "STAT" , "CHGNR" , "USNAM" , "UDATE" , "UTIME" , "TCODE" , "CDTCODE" , "INACT" , "CHIND"
    FROM
    "JCDS"
    WHERE
    "MANDT" = :A0 AND "OBJNR" IN ( :A1 , :A2 , :A3 , :A4 , :A5 )&
    Execution Plan
    V$SQL_PLAN addr= C000000774FF4038 hash= 3408408745 sql_id 4w93fuv5khc59
    SELECT STATEMENT Estimated Costs= 6 Estimated Rows= 0 Optimizer: ALL_ROWS
    3 INLIST ITERATOR
    2 TABLE ACCESS BY INDEX ROWID JCDS
    Estimated Costs= 5 Estimated Rows= 28 Estim. Bytes: 1,848
    Estim. CPU-Costs = 41,426 Estim. IO-Costs = 5
    1 INDEX RANGE SCAN JCDS~0
    Estimated Costs= 1 Estimated Rows= 28 Access predicates:
    "MANDT"=:A0 AND (("OBJNR"=:A1 OR "OBJNR"=:A2 OR "OBJNR"=:A3 OR "OBJNR"=:A4
    OR "OBJNR"=:A5)) Search Columns: 2 Estim. CPU-Costs = 6,777 Estim. IO-Costs = 1
    Program Data:
    Origin of ABAP coding
    Program Name Line  Created By Last Changed By Last Changed On
    LPSSTU03      44     SAP          SAP               25.03.2003
    000044 SELECT * FROM JCDS
    000045 APPENDING CORRESPONDING FIELDS OF TABLE T_JCDS
    000046 FOR ALL ENTRIES IN R_OBJNR
    000047 WHERE OBJNR = R_OBJNR-OBJNR.

  • Expensive SQL Statements

    Hi all,
             Am a new bee to this group I'll be greateful if any one help me in understanding about the Expensive SQL Statements.why n where thy r used
    Thanks..
    Mohammed

    Hi shankaran,
    1. Is there any way in finding out the expensive sql statements been used in a program.
      There is no direct way to find out.
    2. Only when the program is run,  
       and thru basis tcodes/performance testing tcodss,
      can we know whether some sqls are very heavy !
    3. PERFORMANCE TUNING IS VERY SENSITIVE TOPIC
    4. There are some basic recommendatations.
       a) don't use select *, just use select fied1,field2
       b) Incrase the fileter criteria (ie. more where conditions to narrow down the search cretierai)
       c) Create secondar indexes on columns 
        of tables, which are frequently
       used in programs.
    regards,
    amit m.

  • Expensive SQL statements & no proper indexing INCLUDE LBSVAU14-BSVA FuncGrp

    Expensive SQL statements & no proper indexing INCLUDE LBSVAU14 - Function Group BSVA (Status management)
    Hi there Forum
    During a recent upgrade we have implemented EhP4 with relevant Support Packs.
    Our Early Watch Report nows highlights INCLUDE LBSVAU14 as having expensive SQL statements along with improper indexing.
    Although I have seached through OSS and Forums I can find nothing of help.
    Is there an EXPERT out there who can help because SAP tell me that is the way it works!
    Thanks.
    Carl Cavendish-Davies

    Herewith the latest results from the Early Watch report on this:
    Object Type     Total Executions         Disk Reads   Elapsed Time   Buffer Gets    Records Processed
    TABLE     457663                 3282704       21081305        28310151       20031340
    SELECT
    FROM
    "JEST"
    WHERE
    "MANDT" = :A0 AND "OBJNR" IN ( :A1 , :A2 , :A3 , :A4 , :A5 )&
    Execution Plan
    V$SQL_PLAN addr= C000000774FF4038 hash= 3408408745 sql_id 4w93fuv5khc59
    SELECT STATEMENT Estimated Costs= 3 Estimated Rows= 0 Optimizer: ALL_ROWS
    3 INLIST ITERATOR
    2 TABLE ACCESS BY INDEX ROWID JEST
    Estimated Costs= 3 Estimated Rows= 10 Estim. Bytes: 330
    Estim. CPU-Costs = 20,886 Estim. IO-Costs = 3
    1 INDEX RANGE SCAN JEST~0
    Estimated Costs= 1 Estimated Rows= 10 Access predicates:
    "MANDT"=:A0 AND (("OBJNR"=:A1 OR "OBJNR"=:A2 OR "OBJNR"=:A3 OR "OBJNR"=:A4
    OR "OBJNR"=:A5)) Search Columns: 2 Estim. CPU-Costs = 6,137 Estim. IO-Costs = 1
    Program Data:
    Origin of ABAP coding
    Program Name       Line     Created By     Last Changed By    Last Changed On
    LBSVAU14            110     SAP     SAP              08.04.2007
    000110 SELECT * FROM JEST CLIENT SPECIFIED
    000111 APPENDING TABLE JEST_BUF
    000112 FOR ALL ENTRIES IN OBJNR_TAB
    000113 WHERE MANDT EQ CLIENT
    000114 AND OBJNR = OBJNR_TAB-OBJNR.

  • Expensive SQL statements & no proper indexing INCLUDE LBSVAF14-BSVA FuncGrp

    Expensive SQL statements & no proper indexing INCLUDE LBSVAF14 - Function Group BSVA (Status management)
    Hi there Forum
    During a recent upgrade we have implemented EhP4 with relevant Support Packs.
    Our Early Watch Report nows highlights INCLUDE LBSVAF14 as having expensive SQL statements along with improper indexing.
    Although I have seached through OSS and Forums I can find nothing of help.
    Is there an EXPERT out there who can help because SAP tell me that is the way it works!
    Thanks.
    Carl Cavendish-Davies

    Herewith the latest results from the Early Watch report on this:
    Cache Statistics
    Object Type     Total Executions     Disk Reads     Elapsed Time     Buffer Gets     Records Processed
    TABLE     1716707                            1854501     13325961     25580720     19606427
    SELECT
    FROM
    "JEST"
    WHERE
    "MANDT" = :A0 AND "OBJNR" = :A1&
    Execution Plan
    V$SQL_PLAN addr= C000000774FF4038 hash= 3408408745 sql_id 4w93fuv5khc59
    SELECT STATEMENT Estimated Costs= 2 Estimated Rows= 0 Optimizer: ALL_ROWS
    2 TABLE ACCESS BY INDEX ROWID JEST
    Estimated Costs= 1 Estimated Rows= 2 Estim. Bytes: 66
    Estim. CPU-Costs = 8,804 Estim. IO-Costs = 1
    1 INDEX RANGE SCAN JEST~0
    Estimated Costs= 1 Estimated Rows= 2
    Access predicates: "MANDT"=:A0 AND "OBJNR"=:A1 Search Columns: 2
    Estim. CPU-Costs = 5,817 Estim. IO-Costs = 1
    Program Data:
    Origin of ABAP coding
    Program Name       Line     Created By     Last Changed By   Last Changed On
    LBSVAF14           81     SAP     SAP             08.04.2007
    000080 * Einzelstatus von DB lesen in interne Tabelle
    000081 SELECT * FROM JEST CLIENT SPECIFIED
    000082 APPENDING TABLE JEST_TAB
    000083 WHERE MANDT = MANDT
    000084 AND OBJNR = OBJNR.

  • Expensive SQL statements & no proper indexing in INCLUDE LV70AF01-SAPLV70A

    Hi there forum
    During a recent upgrade we have implemented EhP4 with relevant Suppoert Packs.
    Our Early Watch Report nows highlights INCLUDE LV70AF01 in Module SAPLV70A as havinf a multitude of expensive SQL statements along with improper indexing.
    Although I have seached through OSS and Forums I can find nothing of help.
    Is there an EXPERt out there who can help because SAP tell me that is the way it works!
    Thanks.
    Carl Cavendish-Davies

    Herewith the results of our latest Early Watch report on this issue:
    Statement Data:
    Cache Statistics
    Object Type     Total Executions Disk Reads     Elapsed Time     Buffer Gets     Records Processed
    TABLE     261         1107862     11465343     170865092     4
    SELECT
    FROM
    "NAST"
    WHERE
    "MANDT" = :A0 AND "KAPPL" = :A1 AND "KSCHL" = :A2 AND "NACHA" = :A3 AND "VSTAT" = :A4 AND "VSZTP" = :A5 AND "AKTIV" = :A6&
    Execution Plan
    V$SQL_PLAN addr= C000000774FF4038 hash= 3408408745 sql_id 4w93fuv5khc59
    SELECT STATEMENT Estimated Costs= 1,338 Estimated Rows= 0 Optimizer: ALL_ROWS
    2 TABLE ACCESS BY INDEX ROWID NAST
    Estimated Costs= 1,338 Estimated Rows= 150
    Filter predicates: ("NACHA"=:A3 AND "VSTAT"=:A4 AND "VSZTP"=:A5)
    Estim. Bytes: 41,700 Estim. CPU-Costs = 13,539,142 Estim. IO-Costs = 1,336
    1 INDEX RANGE SCAN NAST~I
    Estimated Costs= 19 Estimated Rows= 8,093 Filter predicates: "AKTIV"=:A6
    Access predicates: "MANDT"=:A0 AND "KAPPL"=:A1 AND "KSCHL"=:A2 AND "AKTIV"=:A6
    Search Columns: 4 Estim. CPU-Costs = 988,073 Estim. IO-Costs = 19
    Program Data:
    Origin of ABAP coding
    Program Name Line Created By Last Changed By Last Changed On
    LV70AF01      930  SAP         SAP               07.06.2001
    000930 SELECT * FROM nast INTO TABLE ct_messages
    000931 WHERE kappl IN irt_application
    000932 AND kschl IN irt_type
    000933 AND nacha IN irt_medium
    000934 AND vstat IN irt_status
    000935 AND vsztp IN irt_timing
    000936 AND aktiv EQ space.

  • Expensive SQL statements in EWA

    Hi experts,
    how can I add expensive SQL statements to Early watch alert reports? In my IDES system this is generated automatically but not for different other systems. Can this be activated by specific settings?
    Thanks and best regards, Basti

    Hi bd,
    Please check these points:
    What database are you using?
    What is the version of the ST-SER in your solution manager?
    Is the service preparation finished in the managed system(run se38 -> RTCCTOOL to check)?
    Have you checked note 1564508?
    Besides that, do you see any issue in the SDCCN collection logs for the EWA?
    Regards,
    Daniel.

  • Expensive SQL Statements of the day?

    Hi...
    How can i find out Expensive SQL Statements of the day please.?
    Our SAP Version is ECC 6.0 on Oracle 10.2.0.4.0
    Rgds

    Hi Srinivas,
    On ECC 6.0, go to ST04 t-code --> performance --> SQL Cache --> You see SQL Statements where you need to sort by SQL Statements by Total Execution Time(ms).
    I have tried on one of my R/3 4.7EE system, ST04n --> Resource COnsumption --> Top SQL Statements --> you will see 50 Top most expensive SQL Statements interms of wait time.
    also Read: [Re: Diagnosis of the expensive ABAP programs having database time > 90%;
                      [Please Read before Posting in the Performance and Tuning Forum;
    Regards,
    Kanthi Kiran

  • High Database server load from expensive SQL statements

    Dear all,
    I am facing problem in the production  sever there is high Database server load from expensive SQL statements as per EVA report
    Buffer Load [%]     Disk Load [%]     CPU Load [%]
    55     69     0
    Analysis of DB SQL CACHE
    EXPENSIVE SQL STATEMENTS OVERVIEW
    Object Name     CPU Load [%]     I/O Load [%]     Elapsed Time [%]     Executions     Records Processed
    BSIS        1     9     0     22     90462
    CDEF$     6     6     0     2131113     2575694
    BSAD     1     3     0     21     408576
    MKPF     1     32     0     180     3899
    ICOL$     9     1     0     2575694     8703798
    OBJ$     6     1     0     3405254     3400023
    COL$     12     0     0     2138793     22919657
    MKPF     1     13     0     75     396
    MCHB     7     0     0     366543     41708
    Please suggest the step by step to reduce  the  expensive SQL  from these table.
    Regards

    Hi,
    In tx code ST05 i have find the following deatails.
    Duration |Obj. name |Op.    |Recs.|RC    |Statement  
         4 TSP03A     REOPEN             0 SELECT WHERE "NAME" = 'LOCL' AND "P" = 'S_CLIENTS'                                                                                344 TSP03A     FETCH       1      0                                                                                42 ZRIN    DECLARE            0 SELECT WHERE "MANDT" = :A0 AND "BCQ" = :A1                                                                                442 ZRIN    PREPARE            0 SELECT WHERE "MANDT" = :A0 AND "BCQ" = :A1                                                                                3 ZRIN    OPEN               0 SELECT WHERE "MANDT" = '600' AND "BCQ" = 'BCQ'                                                                               
    2,181,565 ZRIN  FETCH       4   1403                                                                               
    706,267 DBA_SEGME FETCH      99      0                                                                                8,248 DBA_SEGME FETCH      99      0                                                                                44,994 DBA_SEGME FETCH      99      0                                                                                67,713 DBA_SEGME FETCH      99      0   
    1,367,923 DBA_SEGME FETCH      99      0
      16,735|TADIR     |FETCH  |    1|  1403|                                                                                |
    5
    TADIR
    REOPEN
    0
    SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CME__TEXT'
    22,415
    TADIR
    FETCH
    1
    1403
    4
    TADIR
    REOPEN
    0
    SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CME_PATTERN_SIGN'
    232
    TADIR
    FETCH
    1
    1403
    4
    TADIR
    REOPEN
    0
    SELECT WHERE "PGMID" = 'R3TR' AND "OBJECT" = 'TABL' AND "OBJ_NAME" = 'CML_ARC_DEADLINE'
    19,189
    TADIR
    FETCH
    1
    1403
    4
    TADIR
    REOPEN
    706,267
    DBA_SEGME
    FETCH
    99
    0
    |
    44,994
    DBA_SEGME
    FETCH
    99
    0
    67,713
    DBA_SEGME
    FETCH
    99
    0
    Please suggest how to  reduce it.
    Regards,

  • Expensive SQL Statement

    Hi Guys,
    I have just received an email from our basis team where they said I am using an expensive SQL statement.
    There is a loop on a table of people with the following statement
        SELECT * FROM catsdb INTO TABLE w_cats
          WHERE arbid EQ i_data-arbid
          AND   raufpl EQ i_data-aufpl
          AND   raplzl EQ i_data-aplzl
          AND   workdate IN s_wdate
          AND   status EQ '30'.
    Is it me or is this the quickest way possible??
    Can anyone think of a better way to do this??
    Thanks Experts

    First of all, did you ever hear about indices? Please check whether there is an index (SE11) with has fields of your WHERE-condition.
    => if this is not the case the it will be slow, until an index is created.
    Second, change the LOOP into a FOR ALL ENTRIES, don't forget to check whether the itab is initial.

  • Oracle Spatial operator SQL statement help

    I have a 3D elevation point feature class (elev) and a polygon feature class (Building) loaded in Oracle Spatial. I am trying to update the "HEIGHT" attribute of the "Building" Feature class using the average elevation of "elev" feature class. Here below is the SQL statement I used, which generated the same value for all buildings. The avg(elevation) returns the average elevation of all points within all building polygons, not all points within ONE polygon.
    Please help and thanks.
    update building
    set height = (select avg(elevation)
    from elev e, building b
    where sdo_anyinteract(e.shape, b.shape) = 'TRUE');

    Hi,
    try this
    update building b
    set height = (select avg(elevation)
    from elev e where sdo_anyinteract(e.shape, b.shape) = 'TRUE');
    Udo

  • SQL statement help

    If someone would be so kind, I need help in formulating a SQL statement.
    Table A - employees(empoyee_id, employee_name, status)
    This table contains all employees
    employee status can be one of three values (A=active, T=temporary, I=inactive)
    Table B - savings_program(employee_id, plan_type)
    This table only has employee_id's of those that participate in a savings program (subset of all employees).
    plan_type can be one of three numeric values (30,35,40)
    I need SQL to report a.employee_id,a.employee_name,b.plan_type (return plan_type 30,35, or none)of all active employees in Table A that don't participate in Table B plan_type 40.
    Working with version 9iR2. Thanks!
    Edited by: fosterk on Nov 21, 2008 12:59 PM

    The tables and columns above were for demo purposes but actual code I'm trying is below. Please excuse me I'm more of an SA type so SQL is not my thing.
    As you can see from the first SQL statement below I know that I have exactly
    3,000 employees that meet this criteria. The second SQL statement is my attempt to return the rows I want (I'm just nesting it in a count(*) until the numbers look right)
    The last statement is what was given to me by someone else (seeking my help haha) trying to resolve it and it only returns 3 rows. This SQL shows the actual columns that we're trying to return from both tables.
    HR> select count(*) from ps_All_employees where empl_status != 'T'
    2 and emplid not in
    3 (select emplid from ps_savings_pt_vw where plan_type = 40)
    4 /
    COUNT(*)
    3000
    HR> select count(*) from (
    2 (select * from ps_all_employees where empl_status != 'T') a left outer join
    3 (select emplid from ps_savings_pt_vw where plan_type != 40) s
    4 on a.emplid = s.emplid
    5 )
    6 /
    COUNT(*)
    4587
    select count(*) from (
    select a.location, a.ssn, a.first_name, a.last_name, a.birthdate, a.orig_hire_dt, a.hire_dt, a.location, a.street1,
    a.street2, a.city, a.state, a.zip, s.plan_type
    from ps_all_employees a, ps_savings_pt_vw s
    where a.empl_status != 'T' and
    a.emplid = s.emplid and
    a.emplid not in (select s.emplid from ps_savings_pt_vw s where s.plan_type = 40)
    COUNT(*)
    3

  • Native SQL Statement help!

    Hi guys,
    I need some help here.
    I have a requirement to select from Microsoft SQL database
    Question
    How do I select with RANGE internal tables? As you can see, I have 4 range tables for this.
    BElow are my codes
    EXEC SQL.
        CONNECT TO 'CONNECTION_NAME'
      ENDEXEC.
      IF sy-subrc <> 0.
        MESSAGE 'Unable to connect to CONNECTION_NAME' TYPE 'E' DISPLAY LIKE 'I'.
        RETURN.
      ENDIF.
    * Define database cursor
      EXEC SQL.
        OPEN dbcur FOR
                SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
                       qty, zopcd, bstnk, wekunnr
                  FROM <TABLE_NAME>
                 WHERE month IN i_month
                   AND yyear IN i_year
                   AND kunnr IN i_kunnr
                   AND bstnk IN i_bstnk
      ENDEXEC.
    * Fill itab
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :l_dest-name1,
                                :l_dest-zvctk,
                                :l_dest-kunnr,
                                :l_dest-yyear,
                                :l_dest-mmonth,
                                :l_dest-matnr,
                                :l_dest-qty,
                                :l_dest-zopcd,
                                :l_dest-bstnk,
                                :l_dest-wekunnr
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          APPEND l_dest TO it_dest.
        ENDIF.
      ENDDO.
    its giving me a shortdump
    >>>>>     OPEN dbcur FOR
       35             SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
       36                    qty, zopcd, bstnk, wekunnr
       37               FROM v_promise_sa
       38              WHERE month IN i_month[]
       39                AND yyear IN i_year[]
       40                AND kunnr IN i_kunnr[]
       41                AND bstnk IN i_bstnk[]
    Error message:
    Database error text........: "[Microsoft][SQL Server Native Client 10.0][SQL
    Server]Incorrect syntax near 'i_month'."
    Database error code........: 102
    Triggering SQL statement...: "SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
    qty, zopcd, bstnk, wekunnr FROM <TABLE_NAME> WHERE month IN i_month[] AND
    yyear IN i_year[] AND kunnr IN i_kunnr[] AND bstnk IN i_bstnk[]"
    Internal call code.........: "[DBDS/NEW DSQL]"
    Please check the entries in the system log (Transaction SM21).
    Can anyone guide me? If I do not enter the where clause, it is selecting fine.
    Appreciate it guys! Thanks in advance!

    lol, Come guys, don't judge me by just my forum nick man. It was just something random during registration a few years back...was indeed new in ABAP language :P
    But anyway, the table v_promimse_sa is not in the DDIC, its some microsoft MYSQL database or something.
    anyway what I did now:
    EXEC SQL.
        CONNECT TO 'MSSQL_PROMISE'
      ENDEXEC.
      IF sy-subrc <> 0.
        MESSAGE 'Unable to connect to MSSQL_PROMISE' TYPE 'E' DISPLAY LIKE 'I'.
        RETURN.
      ENDIF.
    * Define database cursor
      EXEC SQL.
        OPEN dbcur FOR
                SELECT name1, zvctk, kunnr, yyear, mmonth, matnr,
                       qty, zopcd, bstnk, wekunnr
                  FROM v_promise_sa
                 WHERE mmonth = :i_month
                   AND yyear  = :i_year
    *               AND ( kunnr BETWEEN :i_kunnr-low AND :i_kunnr-high )
    *               AND ( bstnk BETWEEN :i_bstnk-low AND :i_bstnk-high )
      ENDEXEC.
    * Fill itab
      DO.
        EXEC SQL.
          FETCH NEXT dbcur INTO :l_dest-name1,
                                :l_dest-zvctk,
                                :l_dest-kunnr,
                                :l_dest-yyear,
                                :l_dest-mmonth,
                                :l_dest-matnr,
                                :l_dest-qty,
                                :l_dest-zopcd,
                                :l_dest-bstnk,
                                :l_dest-wekunnr
        ENDEXEC.
        IF sy-subrc <> 0.
          EXIT.
        ELSE.
          APPEND l_dest TO it_dest.
        ENDIF.
      ENDDO.
    *    EXEC SQL.
    *      CLOSE dbcur
    *    ENDEXEC.
      DELETE it_dest WHERE kunnr NOT IN i_kunnr
                       AND bstnk NOT IN i_bstnk.
    Well, after checking with the functional person, there are only 3 records so I guess the selection + filtering is working.

  • SQL statements:help

    here is a sample code of my application....
    int initialDelay = 10000; // start after 10 second
    int period = 10000*60*60*24*30; // repeat every month
    Timer timer = new Timer();
    TimerTask task = new TimerTask() {
    public void run() {
    try {
    MyDBConnection jdbc = new MyDBConnection();
    jdbc.init();
    Connection conn = jdbc.getMyConnection();
    Statement stmt = conn.createStatement();
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    String[] tbl = {"emticket","emattachment","emhistory","emtracker"};
    progTxt.setText("");
    Logs l = new Logs();
    l.append("Auto Archive");
    date.getTime();
    //Archive data
    progTxt.append("\n\n");
    progTxt.append(" Archiving Data...\n ");
    stmt.execute("select * into outfile 'c:/emticket " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by '\\n' from emticket where RcvDateTime between date_sub(curdate(),interval 90 day) and curdate()");
    stmt.execute("select * into outfile 'c:/emattachment " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by '\\n' from emattachment where EmID in (select EmID from emticket where RcvDateTime between date_sub(curdate(),interval 90 day) and curdate())");
    stmt.execute("select * into outfile 'c:/emhistory " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by '\\n' from emhistory where TicketID in (select TicketID from emticket where RcvDateTime between date_sub(curdate(),interval 90 day) and curdate())");
    stmt.execute("select * into outfile 'c:/emtracker " + dateFormat.format(date) + ".csv' fields terminated by ',' enclosed by '\"' lines terminated by '\\n' from emtracker where TicketID in (select TicketID from emticket where RcvDateTime between date_sub(curdate(),interval 90 day) and curdate())");
    progTxt.append("Done.\n\n");
    //Delete data
    progTxt.append(" Deleting Data... ");
    stmt.execute("delete emticket, emattachment, emhistory, emtracker from emticket, emattachment, emhistory, emtracker where emattachment.EmID=emticket.EmID and emhistory.TicketID=emticket.TicketID and emtracker.TicketID=emtracker.TicketID and where RcvDateTime
    "_______"DATE_SUB(CURDATE(),INTERVAL 90 DAY) and CURDATE())");
    System.out.println(stmt.getUpdateCount());
    progTxt.append("Done.\n\n");
    Here's what i want to do....I want to backup file for the current date back to 3 mos...e.g 2007-05-23 down to 2007-02-23...then delete the remaining records...before"02-23-2007 to 05-23-2007"....this is where the query part i that doesn't work....
    Delete data
    progTxt.append(" Deleting Data... ");
    stmt.execute("delete emticket, emattachment, emhistory, emtracker from emticket, emattachment, emhistory, emtracker where emattachment.EmID=emticket.EmID and emhistory.TicketID=emticket.TicketID and emtracker.TicketID=emtracker.TicketID and where RcvDateTime
    "_______"DATE_SUB(CURDATE(),INTERVAL 90 DAY) and CURDATE())");
    System.out.println(stmt.getUpdateCount());
    progTxt.append("Done.\n\n")
    I tried putting <>=which means not equal in the "_____"but it fails to work..can somebody help me to work out with this query.

    I don't know MySQL, but shouldn't you just use <= ? I also don't understand what the final part 'and CURDATE()' is for...

Maybe you are looking for