Help with a select statement

I have a table in the folowing format:
date(dd/mm/yyyy) comments(varchar2)
04/09/2007 abcd
04/09/2007 efghij
07/09/2007 klmn
08/09/2007 opqrs
08/09/2007 tuvwxyz
I trying to write a SQL to give me the length of
longest concatenated string of "comments' among the dates.
eg. the query should return : 12 , because date '08/09/2007'
has the longest string when concatenated.
thanks in advance.

I am not sure if the use of the row_number function inside the following query works on 10.1.0.5. If you have troubles, you'd have to nest the row_number analytic function a level deeper.
This one works on 10gR2:
SQL> select max(c) keep (dense_rank last order by length(c)) comments
  2    from ( select mydate
  3                , rn
  4                , c
  5             from mytable
  6            model
  7                  partition by (mydate)
  8                  dimension by (row_number() over (partition by mydate order by comments) rn)
  9                  measures (cast(comments as varchar2(100)) c)
10                  rules
11                  ( c[any] order by rn desc = c[cv()] || c[cv()+1]
12                  )
13         )
14   where rn = 1
15  /
COMMENTS
opqrstuvwxyz
1 rij is geselecteerd.Note that there isn't a column present that decides which comment should be before another comment.
Regards,
Rob.

Similar Messages

  • Help with a select statement from a SQL Server within a DTS !!

    Hello Gurus!
    I help with the script bellow, when I run it within DTS (in SQL Sever 2000), I got the error Invalid number/or not a valid month.
    Please bellow with the WHERE CLASUE '08/01/2001' AND '03/09/2002'
    And in the other hand I change this forma to '01-AUG-01' AND
    '03-MAR-2002', the DTS start and run witha successful messages, but it does not returns row, which is wrong.
    Somebady please help!
    Thanks Gurus!
    GET Total ANIs with Trafic By Area Code
    select
         substr(b.ct_num, 0,3) as Area_Codes,
         COUNT(DISTINCT B.CT_NUM) AS ANIS
    from
         wasabi.v_trans A,
         wasabi.V_Sur_Universal B,
         wasabi.V_Sub C,
         wasabi.V_Trans_Typ D
    where
         D.Trans_typ = A.Trans_Typ AND
         A.Sur_ID = B.Sur_ID AND
         C.Sub_ID = A.Sub_ID AND
         a.trans_stat != 'X' AND     
         a.Trans_DTTM >= '08/01/2001'AND
         a.Trans_DTTM < '03/09/2002 AND
         B.AMA3 = 'PHONE1'
         AND C.SUB_ID not in (100117)
    GROUP BY
         substr(b.ct_num, 0,3)
    ORDER BY
         Area_Codes

    I think that you need a "to_date" function eg
    change '08/01/2001' to to_date('08/01/2001','dd/mm/yyyy')

  • Quick help with a select statement...

    Hello all,
    I will try to lay this out as simply as possible.  I have the following table in my code:
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table.
    I then run through a select statement as follows:
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    That works fine.  The next statement, in the report, is the following select.  When this next select runs it clears all of the fields except for vbeln and erdat.  I want c~vbeln to go into it_table-so_vbeln.  Now it is going into it_table-vbeln.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
        FROM lips AS a
          INNER JOIN vbap AS b ON b~vbeln = a~vgbel
          AND b~posnr = a~vgpos
            INNER JOIN vbak AS c ON c~vbeln = b~vbeln
            FOR ALL ENTRIES IN it_table
              WHERE a~vgbel = it_table-vgbel.
    Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table?  Also, is there a way to combine the two selects into one join? 
    Regards,
    Davis

    Following is the entire report, if that makes it easier:
    *& Report  Z_TRANS_EVAL
    REPORT  z_trans_eval.
    TABLES: likp, lips, adrc, vbpa.
    TYPE-POOLS: truxs.
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table,
          wa_table LIKE LINE OF it_table,
          it_table_csv TYPE truxs_t_text_data.
    DATA : lv_tabix LIKE sy-tabix.
    DATA temp_string TYPE string.
    DATA w_adrnr TYPE vbpa-adrnr.
    DATA: w_adrnr_sp TYPE vbpa-adrnr.
    * Selction criteria
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
    SELECT-OPTIONS: so_vstel FOR likp-vstel,
                    so_wadat FOR likp-wadat_ist,
                    so_mtart FOR lips-mtart.
    SELECTION-SCREEN END OF BLOCK b2.
    * CSV output filename
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
    PARAMETERS: p_file(30) TYPE c.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b3.
    START-OF-SELECTION.
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    * Get internal address number for ship to party
      LOOP AT it_table INTO wa_table.
        lv_tabix = sy-tabix.    "update counter.
        SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
        vbeln = wa_table-vgbel
        AND parvw = 'WE'.
        SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
          vbeln = wa_table-vbeln
          AND parvw = 'SP'
          AND  posnr = '000000'.
        SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
          lifnr = wa_table-lifnr.
    * Get address data from VBPA
        SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
        FROM adrc WHERE
        addrnumber = w_adrnr.
        ENDSELECT.
    * Update the internal table
        MODIFY  it_table INDEX lv_tabix FROM wa_table.
      ENDLOOP.
    END-OF-SELECTION.
    * Call correct display procedure(s).
      IF p_file <> ''.
    * Save a CSV file
        PERFORM display_csv.
      ELSE.
    *Display in ALV
        PERFORM display_alv.
      ENDIF.
    *&      Form  display_alv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_alv .
      DATA: gr_alv TYPE REF TO cl_salv_table,
            gr_func TYPE REF TO cl_salv_functions,
            gr_columns TYPE REF TO cl_salv_columns_table,
            gr_column TYPE REF TO cl_salv_column_table,
            gr_error TYPE REF TO cx_salv_error.
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = gr_alv
            CHANGING
              t_table      = it_table.
        CATCH cx_salv_msg INTO gr_error.
      ENDTRY.
      gr_func = gr_alv->get_functions( ).
      gr_func->set_all( abap_true ).
      gr_alv->display( ).
    ENDFORM.                    " display_alv
    *&      Form  display_csv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_csv .
      DATA: w_filename TYPE string.
      CONCATENATE p_file temp_string INTO w_filename.
      CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
        EXPORTING
          i_field_seperator    = ';'
        TABLES
          i_tab_sap_data       = it_table
        CHANGING
          i_tab_converted_data = it_table_csv
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = w_filename
        TABLES
          data_tab = it_table_csv
        EXCEPTIONS
          OTHERS   = 1.
      PERFORM display_alv.
    ENDFORM.                    " display_csv

  • Need help with a SELECT statement

    Dear forumers,
    I'm a newbie in ABAP and I'm trying to figure out what the following line means (in bold letters):-
    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
    WHERE PERNR = ITAB_DATA-STAFF_NO.
    Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
    Please help and many thanks in advance!

    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2
    WHERE PERNR = ITAB_DATA-STAFF_NO.
    Does this mean that the single data from the STAT2 field is selected and then placed back into the same field (doesn't quite makes sense, right)?
    it sense very much right.
    have you heared about table buffer concept?
    here this concept exactly comes.
    try with this below code:
    TABLES:pa0000."tables must be decleare
    SELECT SINGLE STAT2 FROM PA0000 INTO PA0000-STAT2.
      write:PA0000-STAT2.
    and since you are using select single than you should be use much key as much possible for getting accurate data.other wise system will pick first data which match your where condition.
    Amit.

  • Can you please help with this select statement.

    The following code has a result, I need to modify the select somehow which only gives me the rows which are common between all PLSTS.
    Any suggestions?
    Thank you
    SELECT DISTINCT P.PLST, P.MENU, I,PNL, P.ACCESS
    FROM AUTHITEM P, I.MENUITEM
    WHERE P.MENU = I.MENU
    AND P.PNL = I.PNL
    AND P.MENU IN ('MSN, CPP')
    AND P.ACESS >= 8
    GROUP BY P.PLST, PMENU, I.PNL, P.ACCESS
    HAVING COUNT (*) >=2
    ORDER BY 2,3,4,1
    This is the result with having count > = 1, and if I add having count > =1 I get the following result
    PLST     MENU     PNL     ACCESS
    C001     MSN     LNAME     14
    C002     MSN     LNAME     14
    B008     MSN     LNAME     14
    B005     MSN     FNAME     14
    M009     MSN     LNAME     14
    C001     MSN     GNAME     14
    C002     MSN     GNAME     14
    B008     MSN     LNAME     14
    C001     MSN     FNAME     14
    C002     MSN     FNAME     14
    k008     CPP     MNAME     14
    I need this result
    PLST     MENU     PNL     ACCESS
    C001     MSN     LNAME     14
    C002     MSN     LNAME     14
    C001     MSN     GNAME     14
    C002     MSN     GNAME     14
    C001     MSN     FNAME     14
    C002     MSN     FNAME     14

    why bother with DISTINCT ?
    have a look at the results of :
    SELECT P.PLST, P.MENU, I.PNL, P.ACCESS , COUNT(*) ZCOUNT
      FROM AUTHITEM P, I.MENUITEM
    WHERE P.MENU    = I.MENU
       AND P.PNL     = I.PNL
       AND P.MENU  IN ('MSN, CPP')
       AND P.ACCESS >= 8
    GROUP BY P.PLST, P.PMENU, I.PNL, P.ACCESS
    ORDER BY 2,3,4,1
    ;and then apply HAVING COUNT(*) >= ...

  • I need help with a SELECT query - help!

    Hello, I need help with a select statement.
    I have a table with 2 fields as shown below
    Name | Type
    John | 1
    John | 2
    John | 3
    Paul | 1
    Paul | 2
    Paul | 3
    Mark | 1
    Mark | 2
    I need a query that returns everything where the name has type 1 or 2 but not type 3. So in the example above the qery should bring back all the "Mark" records.
    Thanks,
    Ian

    Or, if the types are sequential from 1 upwards you could simply do:-
    SQL> create table t as
      2  select 'John' as name, 1 as type from dual union
      3  select 'John',2 from dual union
      4  select 'John',3 from dual union
      5  select 'Paul',1 from dual union
      6  select 'Paul',2 from dual union
      7  select 'Paul',3 from dual union
      8  select 'Paul',4 from dual union
      9  select 'Mark',1 from dual union
    10  select 'Mark',2 from dual;
    Table created.
    SQL> select name
      2  from t
      3  group by name
      4  having count(*) <= 2;
    NAME
    Mark
    SQL>Or another alternative if they aren't sequential:
    SQL> ed
    Wrote file afiedt.buf
      1  select name from (
      2    select name, max(type) t
      3    from t
      4    group by name
      5    )
      6* where t < 3
    SQL> /
    NAME
    Mark
    SQL>Message was edited by:
    blushadow

  • Smart scan not working with Insert Select statements

    We have observed that smart scan is not working with insert select statements but works when select statements are execute alone.
    Can you please help us to explain this behavior?

    There is a specific exadata forum - you would do better to post the question there: Exadata
    I can't give you a definitive answer, but it's possible that this is simply a known limitation similar to the way that "Create table as select" won't run the select statement the same way as the basic select if it involves a distributed query.
    Regards
    Jonathan Lewis

  • Need help with the session state value items.

    I need help with the session state value items.
    Trigger is created (on After delete, insert action) on table A.
    When insert in table B at least one row, then trigger update value to 'Y'
    in table A.
    When delete all rows from a table B,, then trigger update value to 'N'
    in table A.
    In detail report changes are visible, but the trigger replacement value is not set in session value.
    How can I implement this?

    You'll have to create a process which runs after your database update process that does a query and loads the result into your page item.
    For example
    SELECT YN_COLUMN
    FROM My_TABLE
    INTO My_Page_Item
    WHERE Key_value = My_Page_Item_Holding_Key_ValueThe DML process will only return key values after updating, such as an ID primary key updated by a sequence in a trigger.
    If the value is showing in a report, make sure the report refreshes on reload of the page.
    Edited by: Bob37 on Dec 6, 2011 10:36 AM

  • Update with a select statement

    hi experts,
    I need some help again.. :)
    I have an insert query here with a select statement.. Juz wondering how to do it in update?
    insert into newsmail_recipient
            (IP_RECIPIENTID,NF_LISTID,NF_STATUSID,D_CREATED,D_MODIFIED,C_NAME,C_EMAIL,USER_ID,NEWSMAIL_ID)
            select newsmail_recipientid_seq.nextval
              , liste
              , 1
              , sysdate
              , sysdate
              , null
              , null
              , ru.nf_userid
              , null
            from roleuser ru, unit u, userinfo ui
            where u.ip_unitid = ru.nf_unitid
            and u.ip_unitid = unit_id
            and ui.ip_userid = ru.nf_userid
            and ui.nf_statusid = 1
            and n_internal = 0
            and ui.ip_userid not in (select user_id
                                       from newsmail_recipient
                                      where user_id = ui.ip_userid
                                        and nf_listid = liste
                                        and nf_statusid = 1);let me know your thoughts.
    Regards,
    jp

    Hi,
    924864 wrote:
    ... I have an insert query here with a select statement.. Juz wondering how to do it in update?How to do what, exactly?
    MERGE can UPDATE existing rows, and INSERT new rows at the same time. In a MERGE statement, you give a table or a sub-query in the USING clause, and define how rows from that result set match rows in your destination table. If rows match, then you can UPDATE the matching row with values from the sub-query.
    Very often, MERGE is easier to use, and perhaps more efficient, than UPDATE just for changing existing rows. That is, while MERGE can do both INSERT and UPDATE, it doesn't have to . You can tell MERGE just to do one or the other if you wish.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Since you're asking about a DML statement, such as UPDATE, the sample data will be the contents of the table(s) before the DML, and the results will be state of the changed table(s) when everything is finished.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Help with this update statement..

    Hi everyone,
    I am trying to update a column in a table .I need to update that column
    with a function that takes patient_nbr and type_x column values as a parameter.
    That table has almost "300,000" records. It is taking long time to complete
    almost 60 min to 90 min.
    Is it usual to take that much time to update that many records?
    I dont know why it is taking this much time.Please help with this update statement.
    select get_partner_id(SUBSTR(patient_nbr,1,9),type_x) partner_id from test_load;
    (it is just taking 20 - 30 sec)
    I am sure that it is not the problem with my function.
    I tried the following update and merge statements .Please correct me if i am wrong
    in the syntax and give me some suggestions how can i make the update statement fast.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    there is a index on patient_nbr column
    and the statistics are gathered on this table.

    Hi Justin,
    As requested here are the explain plans for my update statements.Please correct if i am doing anything wrong.
    update test_load set partner_id = get_partner_id(SUBSTR(patient_nbr,1,9),type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 3793814442"
    "| Id  | Operation          | Name             | Rows  | Bytes | Cost (%CPU)| Time     |"
    "|   0 | UPDATE STATEMENT   |                  |   274K|  4552K|  1488   (1)| 00:00:18 |"
    "|   1 |  UPDATE            |        TEST_LOAD |       |       |            |          |"
    "|   2 |   TABLE ACCESS FULL|        TEST_LOAD |   274K|  4552K|  1488   (1)| 00:00:18 |"
    merge into test_load a
    using (select patient_nbr,type_x from test_load) b
    on (a.patient_nbr = b.patient_nbr)
    when matched
    then
    update
    set a.partner_id = get_partner_id(SUBSTR(b.patient_nbr,1,9),b.type_x);
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 1188928691"
    "| Id  | Operation            | Name             | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | MERGE STATEMENT      |                  |   274K|  3213K|       |  6660   (1)| 00:01:20 |"
    "|   1 |  MERGE               |        TEST_LOAD |       |       |       |            |          |"
    "|   2 |   VIEW               |                  |       |       |       |            |          |"
    "|*  3 |    HASH JOIN         |                  |   274K|    43M|  7232K|  6660   (1)| 00:01:20 |"
    "|   4 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|  4017K|       |  1482   (1)| 00:00:18 |"
    "|   5 |     TABLE ACCESS FULL|        TEST_LOAD |   274K|    40M|       |  1496   (2)| 00:00:18 |"
    "Predicate Information (identified by operation id):"
    "   3 - access("A"."patient_nbr"="patient_nbr")"Please give some suggestions..
    what's the best approach for doing the updates for huge tables?
    Thanks

  • Need some help with the Select query.

    Need some help with the Select query.
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    select single vkorg abgru from ZADS into it_rej.
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
            VKORG TYPE VBAK-VKORG,
            ABGRU TYPE VBAP-ABGRU,
           END OF IT_REJ.
    This is causing performance issue. They are asking me to include the where condition for this select query.
    What should be my select query here?
    Please suggest....
    Any suggestion will be apprecaiated!
    Regards,
    Developer

    Hello Everybody!
    Thank you for all your response!
    I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
    I had created a Z table with the following fields :
    ZADS :
    MANDT
    VKORG
    ABGRU.
    I had written a select query as below :
    I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table 
    select vkorg abgru from ZADS into it_rej.
    Earlier :
    IT_REJ is a Work area:
    DATA : BEGIN OF IT_REJ,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    Now :
    DATA : BEGIN OF IT_REJ occurs 0,
    VKORG TYPE VBAK-VKORG,
    ABGRU TYPE VBAP-ABGRU,
    END OF IT_REJ.
    I guess this will fix the issue correct?
    PLease suggest!
    Regards,
    Developer.

  • Help needed with a SELECT statement. How can I make it run faster?

    Hi,
    not sure if my brain is just too tired but I can't seem to crack this problem today.
    Here is my scenario.
    I have 2 tables
    TABLE1 (searchId INTEGER, routeId INTEGER);
    TABLE2 (routeId INTEGER, cityId INTEGER);
    There are indexes on all 4 columns.
    (routeId on TABLE1 is a primary key).
    In the data I am using, a given search has more than 500 routes, each route has between 10 and 300 cities among more than 4000 possible different cities.
    Now, what I want to create is the list of route couple, within a certain search, that do not have a single city in common.
    That list should populate a table with the following structure
    TABLE3 (searchId INTEGER, routeId1 INTEGER, routeId2 INTEGER)
    Here is the fastest select statement I have found so far.
    SELECT :searchId, t1.routeId, t2.routeId FROM table1 t1, table1 t2
    WHERE t1.searchId=:searchId AND t2.searchId=:searchId
    AND t1.routeId>t2.routeId
    AND NOT EXISTS (
    SELECT cityId FROM table2
    WHERE routeId=t1.routeId
    INTERSECT
    SELECT cityId FROM table2
    WHERE routeId=t2.routeId);
    But it still seem really slow to me.
    Any suggestion for an improved version is welcome.
    Thanks,
    Martin.
    Title was edited by:
    user453358

    I originaly posted this thread because I tought I was missing something "obvious" that would perform better that would make my SELECT statement perform better.
    So I did not want to go as deep as using TKPROOF yet.
    Here is the statistics I gets on my statement.
      1   SELECT t1.searchId,t1.routeId, t2.routeId id2
      2      FROM table1 t1, table1 t2
      3     WHERE t1.searchid=t2.searchid
      4      AND t1.searchId=91
      5      AND t1.routeId>t2.routeId
      6      AND NOT EXISTS (
      7             SELECT cityId FROM table2
      8              WHERE routeId=t1.routeId
      9             INTERSECT
    10             SELECT cityId FROM table2
    11*            WHERE routeId=t2.routeId)
    SQL> /
    43302 rows.
    Tidsåtgång: 00:01:55.02
    Körschema
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=9 Card=1 Bytes=14)         
       1    0   FILTER                                                             
       2    1     TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=1 Card=1 Bytes=7)                                                
       3    2       NESTED LOOPS (Cost=3 Card=1 Bytes=14)                          
       4    3         TABLE ACCESS (BY INDEX ROWID) OF 'table1' (TABLE) (Cost=2 Card=1 Bytes=7)
       5    4           INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=1 Card=1)                                                    
       6    3         INDEX (RANGE SCAN) OF 'table1_IDX1' (INDEX) (Cost=0 Card=1)                                                      
       7    1     INTERSECTION                                                     
       8    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
       9    8         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
      10    9           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
      11    7       SORT (UNIQUE) (Cost=3 Card=108 Bytes=864)                      
      12   11         TABLE ACCESS (BY INDEX ROWID) OF 'table2' (TABLE) (Cost=2 Card=108 Bytes=864)                                 
      13   12           INDEX (RANGE SCAN) OF 'table2_IDX1' (INDEX) (Cost=1 Card=108)                                               
    Statistik
              1  recursive calls                                                   
              0  db block gets                                                     
        2872765  consistent gets                                                   
              0  physical reads                                                    
            812  redo size                                                         
         964172  bytes sent via SQL*Net to client                                  
          32245  bytes received via SQL*Net from client                            
           2888  SQL*Net roundtrips to/from client                                 
         860256  sorts (memory)                                                    
              0  sorts (disk)                                                      
          43302  rows processed  Looks like a big number of consistent gets! Any idea how to improve on that?
    Martin.

  • Need Help With A Select Staement

    This is my data set.
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
    05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08
    I'm need totals for those that are opened and closed per day. Here is what I'm trying to achieve...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    Open 0 03-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    Open 0 05-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    Close 0 09-JAN-08
    This select statement gets me close but the problem is how to get the ones that should have a Value of 0
    select 'Open' "Status", count(*) "Value", to_char(open_date, 'DD-MON-YY') "DATE"
    from usar_log2
    where open_date IS NOT NULL and
    to_char(open_date, 'MON-YY') = to_char(sysdate, 'MON-YY')
    and (USAR_status like 'CLOSED' or usar_status like 'OPENED' or USAR_Status like 'WORKING')
    group by to_char(open_date, 'DD-MON-YY')
    UNION
    select 'Closed' "status", count(*) "Close", to_char(close_date, 'DD-MON-YY')
    from usar_log2
    where close_date is not null and
    to_char(close_date, 'MON-YY') = to_char(sysdate, 'MON-YY')
    and (USAR_status like 'CLOSED' or usar_status like 'OPENED' or USAR_Status like 'WORKING')
    group by to_char(close_date, 'DD-MON-YY')
    order by 3, 1 desc;
    The above select statement's results...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    But I need this instead...
    Status Value DATE
    Open 6 02-JAN-08
    Closed 3 02-JAN-08
    <----- Open 0 03-JAN-08
    Closed 1 03-JAN-08
    Open 1 04-JAN-08
    Closed 1 04-JAN-08
    <----- Open 0 05-JAN-08
    Closed 1 05-JAN-08
    Open 3 07-JAN-08
    Closed 2 07-JAN-08
    Open 3 08-JAN-08
    Closed 1 08-JAN-08
    Open 1 09-JAN-08
    <----- Close 0 09-JAN-08
    Any help would be more appreciative.

    Thank you...You all are great. While I'm still
    looking at the various ways you all provided, from
    what I have looked at so far, they don't address
    05-JAN-08 which has a null open date. There are
    three possiblities, maybe four. Does 05-JAN-08 have a null open date in the data you supplied?
    You showed us:
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
    05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08
    which looks like they all have open dates.
    Perhaps, if there was null open dates you should have used [code][/code] or [pre][/pre] tags around your data so it looked something like
    OPEN_DATE CLOSE_DATE
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 02-JAN-08
    02-JAN-08 03-JAN-08
    04-JAN-08 04-JAN-08
              05-JAN-08
    07-JAN-08
    07-JAN-08 07-JAN-08
    07-JAN-08 07-JAN-08
    08-JAN-08 08-JAN-08
    08-JAN-08
    02-JAN-08
    02-JAN-08
    08-JAN-08
    09-JAN-08And then it would have required the ANSI outer join in my query to allow for outer joining on more than one column...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (SELECT to_date('02-JAN-2008','DD-MON-YYYY') as open_date, to_date('02-JAN-2008','DD-MON-YYYY') as closed_date from dual union all
      2             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('02-JAN-2008','DD-MON-YYYY') from dual union all
      3             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('02-JAN-2008','DD-MON-YYYY') from dual union all
      4             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), to_date('03-JAN-2008','DD-MON-YYYY') from dual union all
      5             SELECT to_date('04-JAN-2008','DD-MON-YYYY'), to_date('04-JAN-2008','DD-MON-YYYY') from dual union all
      6             SELECT NULL, to_date('05-JAN-2008','DD-MON-YYYY') from dual union all
      7             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), NULL from dual union all
      8             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), to_date('07-JAN-2008','DD-MON-YYYY') from dual union all
      9             SELECT to_date('07-JAN-2008','DD-MON-YYYY'), to_date('07-JAN-2008','DD-MON-YYYY') from dual union all
    10             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), to_date('08-JAN-2008','DD-MON-YYYY') from dual union all
    11             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    12             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    13             SELECT to_date('02-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    14             SELECT to_date('08-JAN-2008','DD-MON-YYYY'), NULL from dual union all
    15             SELECT to_date('09-JAN-2008','DD-MON-YYYY'), NULL from dual)
    16      ,all_dates as (select minod+rownum-1 as dt
    17                     from   dual, (select min(open_date) minod, max(open_date) maxod from t)
    18                     connect by rownum <= maxod-minod+1)
    19      ,stat as (select 'open' as status from dual union all select 'closed' from dual)
    20  -- END OF DATA
    21  select all_dates.dt, stat.status, sum(decode(decode(stat.status, 'open', t.open_date, t.closed_date), all_dates.dt, 1, 0)) as cnt
    22  from   stat JOIN all_dates ON (1=1)
    23         LEFT OUTER JOIN t ON (NVL(t.open_date, NVL(t.closed_date, all_dates.dt)) = all_dates.dt)
    24  group by all_dates.dt, stat.status
    25* order by 1,2 desc
    SQL> /
    DT        STATUS        CNT
    02-JAN-08 open            6
    02-JAN-08 closed          3
    03-JAN-08 open            0
    03-JAN-08 closed          0
    04-JAN-08 open            1
    04-JAN-08 closed          1
    05-JAN-08 open            0
    05-JAN-08 closed          1
    06-JAN-08 open            0
    06-JAN-08 closed          0
    07-JAN-08 open            3
    07-JAN-08 closed          2
    08-JAN-08 open            3
    08-JAN-08 closed          1
    09-JAN-08 open            1
    09-JAN-08 closed          0
    16 rows selected.
    SQL>Make your requirements clear in the future.

  • Help with a CASE statement

    Please help me with a CASE Statement:
    - When ID = 15, 16, 17, 18 then "Bad"
    - when ID = 19, then "Average"
    - when ID = 21, then "Good"
    - else "Null"
    Thank you!!

    Well the 1st thing to do would be to correct my poor spelling... change    Delault : to Default :
    Don't know why you would get an error stating "The result of selection formula must be a boolean". It's working fine on my machine.
    If your ID field is numbers stored text you have a couple different options...
    1) Convert the ID to a number...
    Select  ToNumber({home.noone_ID})
    2) Wrap the ID values in double quotes...
       Case "15", "16", "17", "18" :
          "BAD"
    Even if this were your problem... the error should be something other than the boolean thing...
    Jason

  • Short dump with a select statement

    I have the following select statement (I have also inluded my data statement(s)) and I get a short dump.  The error is as follows:
    <b>What happened?                                                                 
        Error in ABAP application program.                                                                               
    The current ABAP program "ZPARTNER" had to be terminated because one of the
        statements could not be executed.                                                                               
    This is probably due to an error in the ABAP program.                                                                               
    Following a SELECT statement, the data read could not be placed in AN      
        the output area.                                                           
        A conversion may have been intended that is not supported by the           
        system, or the output area may be too small.                                                                               
    Error analysis                                                                 
        An exception occurred. This exception will be dealt with in more detail    
        below. The exception, assigned to the class 'CX_SY_OPEN_SQL_DB', was not   
         caught, which                                                             
         led to a runtime error. The reason for this exception is:                 
        The data read during a SELECT access could not be inserted into the        
        target field.                                                              
        Either conversion is not supported for the target field's type or the      
        target field is too short to accept the value or the data are not in a     
        form that the target field can accept          </b>                            
    it_adrc TYPE TABLE OF adrc,
          wa_adrc LIKE LINE OF it_adrc,
    SELECT addrnumber name1 street city1 region post_code1 tel_number
      FROM adrc INTO TABLE it_adrc
      FOR ALL ENTRIES IN it_detail
      WHERE addrnumber = it_detail-adrnr.
    Regards,
    Davis

    If you only need the fields mentioned in the select query, then follow this:
    TYPES: BEGIN OF ADRC_TYPE,
         ADDRNUMBER LIKE ADRC-ADDRNUMBER,
         NAME1        LIKE ADRC-NAME1,
         STREET        LIKE ADRC-STREET,
         CITY        LIKE ADRC-CITY,
         REGION        LIKE ADRC-REGION,
         POST_CODE1 LIKE ADRC-POST_CODE1,
         TEL_NUMBER LIKE ADRC-TEL_NUMBER,
           END OF ADRC_TYPE,
           ADRC_T_TYPE TYPE TABLE OF ADRC_TYPE.
    DATA: IT_ADRC TYPE ADRC_T_TYPE WITH HEADER LINE.
    IF NOT IT_DETAIL[] IS INITIAL.
    SELECT addrnumber name1 street city1 region post_code1 tel_number
      FROM adrc INTO TABLE it_adrc
      FOR ALL ENTRIES IN it_detail
      WHERE addrnumber = it_detail-adrnr.
    ENDIF.
    Thanks,
    SKJ

Maybe you are looking for

  • Is it possible to populate an information field with the expect docURL?

    Hi, Is it possible to populate an information field with a function that checks for the expected docURL at checkIn time? I need to pass the value of the docURL of the checked in content item to a bpel process. Thanks.

  • SOLAR_EVAL giving Incorrect report for Keywords

    Hi all, We have implemented Solution Manager7.1 for our project during Realization phase. 1. I have added all the Managed systems to the Solution Manager. 2. Created the Project Structure in Solar01. 3. Added Config Nodes in Configuration Tab for all

  • Duplicate Text At page split

    Hello Experts,    I am creating new adobe form and now i am stuck. I have long text in text ID field. I am using include module to pull the text. I have a main subform then i have line item subform then text element. if i have 5 lines in long text it

  • Canon EOS-1D C cr2 files not recog by LR nor Camera Raw

    Any reason why? They're suppose to be the same as EOS-1D X files and LR and CR opens these files fine.

  • Acrobat 8 std printing in XP

    I am sorry if this topic has been covered in this forum, the search "feature" is terrible and keeps returning results for Macintosh. I am printing to paper pdf files that start out as files ranging from 80KB to 200KB.  When I print the files it seems