How to split this select query

Hi all,
Can any one help me to split this single select query into 9 select query.   
select KNA1STCEG VBRKBUKRS VBRKVKORG VBRKVBELN VBRKFKDAT VBRKFKART VBRKVBTYP VBRKVBUND VBRKKUNAG VBRKKUNRG VBRK~NETWR
           VBRKWAERK VBRKFKSTO VBRKSFAKN VBRKLAND1 T001WKUNNR VBRPPOSNR VBRPWERKS VBRPFKIMG VBRPVRKME VBRPPRSDT
           VBRPNETWR VBRPVGBEL VBRPVGPOS VBRPMATNR VBRPPRCTR VBRPCHARG VBRPAUBEL VBRPAUPOS VBRPVBELN T001WAERS T001~BUKRS
           MBEWSTPRS MBEWPEINH MBEWMATNR MBEWBWKEY LIKPLFART LIKPWERKS LIKPVBELN MBEW_RECVSTPRS MBEW_RECV~PEINH
           MBEW_RECVBWKEY MBEW_RECVMATNR CKMLCRBDATJ CKMLCRPOPER CKMLCRSTPRS CKMLCRWAERS CKMLCRPEINH CKMLCRCURTP
           CKMLCRKALNR CKMLCR_RECVSTPRS CKMLCR_RECVWAERS CKMLCR_RECVPEINH CKMLCR_RECVCURTP CKMLCR_RECVBDATJ CKMLCR_RECV~POPER
           CKMLCR_RECV~KALNR
    from ( KNA1
           left outer join VBRK
           on  VBRKKUNRG = KNA1KUNNR
           inner join T001W
           on  T001WKUNNR = VBRKKUNAG
           inner join VBRP
           on  VBRPVBELN = VBRKVBELN
           inner join T001
           on  T001BUKRS = VBRKBUKRS
           left outer join MBEW
           on  MBEWMATNR = VBRPMATNR
           and MBEWBWKEY = VBRPWERKS
           left outer join LIKP
           on  LIKPVBELN = VBRPVGBEL
           inner join MBEW  as MBEW_RECV
           on  MBEW_RECVBWKEY = T001WBWKEY
           and MBEW_RECVMATNR = VBRPMATNR
           inner join CKMLCR
           on  CKMLCRKALNR = MBEWKALN1
           inner join CKMLCR  as CKMLCR_RECV
           on  CKMLCR_RECVKALNR = MBEW_RECVKALN1 )
         where VBRP~WERKS in SP$00005
           and VBRP~MATNR in SP$00008
           and VBRP~CHARG in SP$00009
           and VBRP~AUBEL in SP$00017
           and CKMLCR~CURTP in SP$00015
           and CKMLCR~BDATJ in SP$00013
           and CKMLCR~POPER in SP$00014
           and CKMLCR_RECV~CURTP in SP$00019
           and CKMLCR_RECV~BDATJ in SP$00020
           and CKMLCR_RECV~POPER in SP$00018 .

Hi, it is not good for your performance to split into 9 selects but the select you are now using is also not so good. Start with VBRP instead of KNA1.
You can do it in the following way. For example:
DATA tb_kna1  TYPE STANDARD TABLE OF kna1.
DATA tb_vbrk  TYPE STANDARD TABLE OF vrbk.
DATA tb_vrbp  TYPE STANDARD TABLE OF vrbp.
Start with VRBP for a better performance
SELECT * FROM vrbp
  INTO CORRESPONDING FIELDS OF TABLE tb_vbrp
  WHERE werks IN ....   etc.
SELECT * FROM vbrk
  INTO CORRESPONDING FIELDS OF TABLE tb_vbrk
  FOR ALL ENTRIES IN tb_vrbp
  WHERE vbeln = tb_vrbp-vbeln.
SELECT * FROM kna1
  INTO CORRESPONDING FIELDS OF TABLE tb_kna1
  FOR ALL ENTRIES IN tb_vrbk
  WHERE kunnr = tb_vrbk-kunnr.
Success.

Similar Messages

  • Make this select query to Select Insert query

    Hi,
    How to make this select query to select Insert query..
    ;WITH DateDim AS
    SELECT CAST('1900-01-01' AS DATETIME) StartDate
    UNION ALL
    SELECT StartDate + 1
    FROM DateDim
    WHERE StartDate + 1 <= '2099-12-31'
    SELECT CAST(CONVERT(CHAR(8),CAST(StartDate AS DATETIME),112) AS INT) AS DateKey
    , StartDate
    , DATEPART(dw, StartDate) AS DayNumberOfWeek
    , DATENAME(dw, StartDate) AS EnglishDayNameOfWeek
    , DAY(StartDate) AS DayNumberOfMonth
    , (CASE WHEN MONTH(StartDate)>=1 AND MONTH(StartDate) <=6 THEN 1 ELSE 2 END) AS CalendarSemester
    FROM DateDim 
    OPTION (MAXRECURSION 0) 
    GO

    The final solution is                            
     ;WITH DateDim AS
    SELECT CAST('1900-01-01' AS DATETIME) StartDate
    UNION ALL
    SELECT StartDate + 1
    FROM DateDim
    WHERE StartDate + 1 <= '2099-12-31'
    SELECT CAST(CONVERT(CHAR(8),CAST(StartDate AS DATETIME),112) AS INT) AS DateKey
    , StartDate
    , DATEPART(dw, StartDate) AS DayNumberOfWeek
    , DATENAME(dw, StartDate) AS EnglishDayNameOfWeek
    , DAY(StartDate) AS DayNumberOfMonth
    , (CASE WHEN MONTH(StartDate)>=1 AND MONTH(StartDate) <=6 THEN 1 ELSE 2 END) AS CalendarSemester
    Into new_tablenameFROM
    DateDim 
    OPTION (MAXRECURSION 0) 
    GO

  • How can we split a select query to 3 or 4 if it is fetching much records?

    I am running a query like:
    select * from table_name
    it will be fetching 152940696 records. Now i want to fetch this result as 3 or 4 select statements. That is, in the second query I want to fetch the records from where i stopped in the first query. and similar for the 3rd i have to continue from the 2nd query. And for the 4th query i have to start from where i have stopped in the 3rd query.
    when i tried with rownum we can fetch the records upto < or <= to a particular count like 100000000. But above this count i cannot fetch using rownum. Because > or >= wont work with rownum.
    Is there anyother way to split the select query as i explained.
    Thanks in advance

    I'll assume you want to split the query up for performance reasons.
    The easiest way to do this if you have the license is to use the parallel query option, which can help, hurt or do nothing. The only way to find out is to try. PQO would be best from a performance standpoint if possible, provided it will do what you need.
    Failing that as has been suggested you need a logical, scalable way to divide up the queries. It has already been pointed out that the rownum solution probably will not work correctly. Also, the MINUS with ROWNUM idea has the disadvantage of having to read a lot of the same data twice, making the query run longer.
    Perhaps a range would provide a way to split up the data - something like
    select whatever
      from table
    where primary_key < 10000000;
    select whatever
      from table
    where primary key between 10000001 and 199999999;
    ...

  • How to execute this SQL Query in ABAP Program.

    Hi,
    I have a string which is the SQL Query.
    How to execute this sql Query (SQL_STR) in ABAP Program.
    Code:-
    DATA: SQL_STR type string.
    SQL_STR = 'select * from spfli.'.
    Thanks in Advance,
    Vinay

    Hi Vinay
    Here is a sample to dynamically generate a subroutine-pool having your SQL and calling it.
    REPORT dynamic_sql_example .
    DATA: BEGIN OF gt_itab OCCURS 1 ,
    line(80) TYPE c ,
    END OF gt_itab .
    DATA gt_restab TYPE .... .
    DATA gv_name(30) TYPE c .
    DATA gv_err(120) TYPE c .
    START-OF-SELECTION .
    gt_itab-line = 'REPORT generated_sql .' .
    APPEND gt_itab .
    gt_itab-line = 'FORM exec_sql CHANGING et_table . ' .
    APPEND gt_itab .
    gt_itab-line = SQL_STR .
    APPEND gt_itab .
    gt_itab-line = 'ENDFORM.' .
    APPEND gt_itab .
    GENERATE SUBROUTINE POOL gt_itab NAME gv_name MESSAGE gv_err .
    PERFORM exec_sql IN PROGRAM (gv_name) CHANGING gt_restab
    IF FOUND .
    WRITE:/ gv_err .
    LOOP AT gt_result .
    WRITE:/ .... .
    ENDLOOP .
    *--Serdar

  • Can we replace this SELECT query by more efficient code

    can we replace this SELECT query by more efficient code ?:-
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE ( SENDER in S_SENDER and
                 ORDNUM in S_ORDER  and
                 ZDATE   in S_DATE ) OR
               ( SENDER in S_SENDER AND
                 STATUS = SPACE )
         ORDER BY IDOCNUM.

    Hi
    U can leave ORDER BY option and sort the table by yourself and try to split the query:
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER and
                       ORDNUM in S_ORDER  and
                       ZDATE   in S_DATE .
    SELECT * FROM zv7_custord
         APPENDING TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER        and
                       NOT ORDNUM in S_ORDER  and
                       NOT ZDATE   in S_DATE       and
                       STATUS = SPACE
    or
    SELECT * FROM zv7_custord
         INTO TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER and
                       ORDNUM in S_ORDER  and
                       ZDATE   in S_DATE .
    SELECT * FROM zv7_custord
         APPENDING TABLE G_T_ZV7_CUSTORD
         WHERE  SENDER in S_SENDER        and
                       STATUS = SPACE.
    * Sort the table key fields
    SORT G_T_ZV7_CUSTORD BY <KEY1> <KEY2> .....
    DELETE ADJACENT DUPLICATES FROM G_T_ZV7_CUSTORD COMPARING <KEY1> .....
    Max

  • Please explain this select query

    Hello Experts
    please see this select query.
      select  *  from kna1 where lifnr = '1111111101'.
    while debugging how to see what records this above select query has fetched. please explain me.
    Thanks for all the replies

    Hi madan,
    as explained, you need an ENDSELECT which I think you already have. In debugger, you could see the records fetched between SELECT and ENDSELECT but you will probably get a DUMP because a forbidden database access interrupt is detected.
    If your program does not process the records you have no chance to see them.
    A possible solution is:
    data:
      lt_kunnr type table of kna1-kunnr.
    select * from kna1 where lifnr = '1111111101'.
      append kna1-kunnr to lt_kunnr.
    endselect.
    Now you have the primary key KUNNR of all records fetched in table lt_kunnr.
    Regards,
    Clemens

  • What can i do for removing SINGLE in this select query??

    What can i do for removing SINGLE in this select query given below and also NOT USE 'ENDSELECT'??
    I have defined g_t_zv7_cachemapping as following ::
    DATA : BEGIN OF g_t_zv7_cachemapping OCCURS 0,
             kostl LIKE zv7_cachemapping-kostl,
             END OF g_t_zv7_cachemapping.
    SELECT SINGLE kostl FROM zv7_cachemapping INTO g_t_zv7_cachemapping
               WHERE  auart = g_t_vbak-auart.
            IF sy-subrc = 0 .
            ENDIF.

    Shashank,
    DATA : BEGIN OF g_t_zv7_cachemapping OCCURS 0,
    AUART LIKE zv7_cachemapping-AUART,
    kostl LIKE zv7_cachemapping-kostl,
    END OF g_t_zv7_cachemapping.
    If not g_t_vbak[] is initial.
    SELECT auart kostl
      FROM zv7_cachemapping INTO table g_t_zv7
    for all entries in g_t_vbak
    WHERE auart = g_t_vbak-auart.
    Endif.
    sort : g_t_zv7 by auart , 
              g_t_vbak by auart.
    loop at g_t_vbak.
      READ TABLE g_t_zv7 WITH KEY AUART = g_t_vbak-AUART
                                        BINARY SEARCH.
       IF sy-subrc eq 0.
       ENDIF.
    endloop.
    Pls. reward if useful

  • How to display a select query record in a tool tip?

    hi,
    How to display a select query record in a tool tip?
    for example i have a report employee. when i move the mouse pointer over a employee name, the tool tip should display the respective department id, department name...of that employee name.
    select dep_id, dep_name ....from department where employee.....Is it possible?
    thanks

    Dear Skud,
    Yes its possible..select ''||ename||'' from emp
    other wise you can use jQuery tooptip or some other JScript bundles.
    Thanks and Regards
    Maheswara

  • How to optimize this select statement  its a simple select....

    how to optimize this select statement  as the records in earlier table is abt i million
    and this simplet select statement is not executing and taking lot of time
      SELECT  guid  
                    stcts      
      INTO table gt_corcts
      FROM   corcts
      FOR all entries in gt_mege
      WHERE  /sapsll/corcts~stcts = gt_mege-ctsex
      and /sapsll/corcts~guid_pobj = gt_Sagmeld-guid_pobj.
    regards
    Arora

    Hi Arora,
    Using Package size is very simple and you can avoid the time out and as well as the problem because of memory.  Some time if you have too many records in the internal table, then you will get a short dump called TSV_TNEW_PAGE_ALLOC_FAILED.
    Below is the sample code.
    DATA p_size = 50000
    SELECT field1 field2 field3
       INTO TABLE itab1 PACKAGE SIZE p_size
       FROM dtab
       WHERE <condition>
    Other logic or process on the internal table itab1
    FREE itab1.
    ENDSELECT.
    Here the only problem is you have to put the ENDSELECT.
    How it works
    In the first select it will select 50000 records ( or the p_size you gave).  That will be in the internal table itab1.
    In the second select it will clear the 50000 records already there and append next 50000 records from the database table.
    So care should be taken to do all the logic or process with in select and endselect.
    Some ABAP standards may not allow you to use select-endselect.  But this is the best way to handle huge data without short dumps and memory related problems. 
    I am using this approach.  My data is much more huge than yours.  At an average of atleast 5 millions records per select.
    Good luck and hope this help you.
    Regards,
    Kasthuri Rangan Srinivasan

  • Please help me what other way i can tune this select query..

    Hello Guru,
    I have a select query which retrieve data from 10 tables and around 4 tables having 2-4 Lac record and rest are having 80,000 - 1 Lac record.
    It is taking around 7-8 seconds to fetch 55000 record.
    I was strictly told by the client that i should not use HINTS in my query. My query is below. Please help me what other way i can tune this select query..
    select
    CT.CUST_ID
    ,CT.ROMANISED_SURNAME
    ,CT.SURNAME
    ,CT.ROMANISED_GIVEN_NAME
    ,CT.GIVEN_NAME
    ,CT.ROMANISED_MIDDLE_NAME
    ,CT.MIDDLE_NAME
    ,CT.ROMANISED_NAME_SUFFIX
    ,CT.NAME_SUFFIX
    ,CT.ROMANISED_TITLE
    ,CT.TITLE
    ,CT.ROMANISED_NAME_INITIALS
    ,CT.NAME_INITIALS
    ,CT.NAME_TEXT
    ,CT.CUST_JRNY_ID
    ,RK.REMARK_TYPE
    ,RK.REMARK_ID+CT.CUST_ID as REMARK_ID
    ,RK.REMARK_STATUS
    ,RK.REMARK_TEXT
    ,RK.HOST_ONLY_IND
    ,RK.SUPERVISORY_IND
    ,RK.CUST_COMM_IND
    ,RK.REMARK_SEQ
    ,RK.REMARK_CODE
    ,RK.DEFAULT_CUST_REL_IND
    ,RK.DEFAULT_FLIGHT_SEG_REL_IND
    ,RK.IATA_CODE
    ,RK.ICAO_CODE
    ,CJ.RECORD_LOCATOR "SITA_RECORD_LOCATOR"
    ,Cjv.Record_Locator "ORIGINATOR_RECORD_LOCATOR"
    ,FS.TRAVELLING_GROUP_CODE
    ,CG.GROUP_NAME
    FROM FLIGHT_LEG FL
    ,CUST_FLIGHT_LEG CFL
    ,CUST CT
    ,CUST_REMARK CTR
    ,REMARK RK
    ,FLIGHT_SEG_FLIGHT_LEG FSFL
    ,FLIGHT_SEG FS
    ,CUST_JRNY CJ
    ,CUST_JRNY_VERSION CJV
    ,CUST_GROUP CG
    WHERE FL.OPR_FLIGHT_NUMBER = 1--I_OPR_FLIGHT_NUMBER
    and FL.HISTORY_VERSION_NUMBER = 0
    and FL.DEPARTURE_STATION_CODE = 'DEL'--I_DEPARTURE_STATION_CODE
    and FL.DEPARTURE_DATETIME = TO_DATE('10-DEC-2012 18.45.00', 'DD-MON-YYYY HH24.MI.SS')
    and FL.OPR_SERVICE_PROVIDER_CODE= 'AI'--i_opr_service_provider_code
    and FL.OPR_FLIGHT_SUFFIX = 'A'--NVL(I_OPR_FLIGHT_SUFFIX, FL.OPR_FLIGHT_SUFFIX)
    AND FL.FLIGHT_LEG_ID = CFL.FLIGHT_LEG_ID
    AND CFL.CUST_ID = CT.CUST_ID
    AND FL.FLIGHT_LEG_ID=FSFL.FLIGHT_LEG_ID
    AND FSFL.FLIGHT_SEG_ID=FS.FLIGHT_SEG_ID
    AND CT.CUST_ID = CTR.CUST_ID(+)
    AND CTR.REMARK_ID = RK.REMARK_ID(+)
    AND FL.CUST_JRNY_ID = CJ.CUST_JRNY_ID
    and CJ.CUST_JRNY_ID = CJV.CUST_JRNY_ID
    AND CG.CUST_JRNY_ID(+) = CT.CUST_JRNY_ID
    AND CFL.HISTORY_VERSION_NUMBER = 0
    AND CT.HISTORY_VERSION_NUMBER = 0
    AND NVL(CTR.HISTORY_VERSION_NUMBER,0) = 0
    AND NVL(RK.HISTORY_VERSION_NUMBER,0) = 0
    AND FS.HISTORY_VERSION_NUMBER = 0
    AND FSFL.HISTORY_VERSION_NUMBER = 0
    -- AND CJ.HISTORY_VERSION_NUMBER = 0
    and CJV.VERSION_NUMBER = 0 --- Need to check
    AND NVL(CG.HISTORY_VERSION_NUMBER,0) = 0
    order by CT.CUST_JRNY_ID,CT.CUST_ID;
    The Tables having record:
    select COUNT(*) from FLIGHT_LEG -----241756
    select COUNT(*) from CUST_FLIGHT_LEG---632585
    select COUNT(*) from CUST---240015
    select COUNT(*) from CUST_REMARK---73724
    select COUNT(*) from REMARK---73654
    select COUNT(*) from FLIGHT_SEG_FLIGHT_LEG---241789
    select COUNT(*) from FLIGHT_SEG----260004
    select COUNT(*) from CUST_JRNY----74288
    select COUNT(*) from CUST_JRNY_VERSION----74477
    select COUNT(*) from CUST_GROUP----55819
    Thanks,
    HP..

    Plan hash value: 3771714931
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop |
    | 0 | SELECT STATEMENT | | 10239 | 2949K| | 7515 (1)| 00:01:31 | | |
    | 1 | SORT ORDER BY | | 10239 | 2949K| 3160K| 7515 (1)| 00:01:31 | | |
    |* 2 | HASH JOIN | | 10239 | 2949K| | 6864 (1)| 00:01:23 | | |
    | 3 | PARTITION HASH ALL | | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
    |* 4 | TABLE ACCESS FULL | CUST_JRNY_VERSION | 73687 | 1079K| | 417 (1)| 00:00:06 | 1 | 512 |
    |* 5 | HASH JOIN | | 10239 | 2799K| | 6445 (1)| 00:01:18 | | |
    | 6 | PARTITION HASH ALL | | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
    | 7 | TABLE ACCESS FULL | CUST_JRNY | 73654 | 863K| | 178 (1)| 00:00:03 | 1 | 512 |
    |* 8 | FILTER | | | | | | | | |
    |* 9 | HASH JOIN RIGHT OUTER | | 10239 | 2679K| | 6267 (1)| 00:01:16 | | |
    | 10 | PARTITION HASH ALL | | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
    | 11 | TABLE ACCESS FULL | CUST_GROUP | 55315 | 756K| | 137 (1)| 00:00:02 | 1 | 512 |
    |* 12 | FILTER | | | | | | | | |
    |* 13 | HASH JOIN OUTER | | 10240 | 2540K| 2056K| 6129 (1)| 00:01:14 | | |
    |* 14 | FILTER | | | | | | | | |
    |* 15 | HASH JOIN RIGHT OUTER | | 10242 | 1930K| | 5531 (1)| 00:01:07 | | |
    | 16 | INDEX FAST FULL SCAN | CUST_REMARK_PK | 73677 | 935K| | 190 (0)| 00:00:03 | | |
    |* 17 | HASH JOIN | | 10257 | 1802K| | 5339 (1)| 00:01:05 | | |
    |* 18 | HASH JOIN | | 10257 | 701K| | 3516 (1)| 00:00:43 | | |
    |* 19 | HASH JOIN | | 3963 | 220K| | 2476 (1)| 00:00:30 | | |
    |* 20 | HASH JOIN | | 3963 | 181K| | 1300 (1)| 00:00:16 | | |
    | 21 | PARTITION HASH ALL | | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
    |* 22 | TABLE ACCESS FULL | FLIGHT_LEG | 3963 | 131K| | 728 (1)| 00:00:09 | 1 | 512 |
    |* 23 | INDEX FAST FULL SCAN| FLIGHT_SEG_FLIGHT_LEG_PK | 240K| 3059K| | 571 (1)| 00:00:07 | | |
    | 24 | PARTITION HASH ALL | | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
    |* 25 | TABLE ACCESS FULL | FLIGHT_SEG | 259K| 2531K| | 1175 (1)| 00:00:15 | 1 | 512 |
    | 26 | PARTITION HASH ALL | | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
    |* 27 | TABLE ACCESS FULL | CUST_FLIGHT_LEG | 631K| 8011K| | 1037 (1)| 00:00:13 | 1 | 512 |
    | 28 | PARTITION HASH ALL | | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
    |* 29 | TABLE ACCESS FULL | CUST | 239K| 25M| | 1822 (1)| 00:00:22 | 1 | 512 |
    | 30 | PARTITION HASH ALL | | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
    | 31 | TABLE ACCESS FULL | REMARK | 73623 | 4385K| | 243 (1)| 00:00:03 | 1 | 512 |
    Predicate Information (identified by operation id):
    2 - access("CJ"."CUST_JRNY_ID"="CJV"."CUST_JRNY_ID")
    4 - filter("CJV"."VERSION_NUMBER"=0)
    5 - access("FL"."CUST_JRNY_ID"="CJ"."CUST_JRNY_ID")
    8 - filter(NVL("CG"."HISTORY_VERSION_NUMBER",0)=0)
    9 - access("CG"."CUST_JRNY_ID"(+)="CT"."CUST_JRNY_ID")
    12 - filter(NVL("RK"."HISTORY_VERSION_NUMBER",0)=0)
    13 - access("CTR"."REMARK_ID"="RK"."REMARK_ID"(+))
    14 - filter(NVL("CTR"."HISTORY_VERSION_NUMBER",0)=0)
    15 - access("CT"."CUST_ID"="CTR"."CUST_ID"(+))
    17 - access("CFL"."CUST_ID"="CT"."CUST_ID")
    18 - access("FL"."FLIGHT_LEG_ID"="CFL"."FLIGHT_LEG_ID")
    19 - access("FSFL"."FLIGHT_SEG_ID"="FS"."FLIGHT_SEG_ID")
    20 - access("FL"."FLIGHT_LEG_ID"="FSFL"."FLIGHT_LEG_ID")
    22 - filter("FL"."DEPARTURE_STATION_CODE"='DEL' AND "FL"."DEPARTURE_DATETIME"=TO_DATE(' 2012-12-10 18:45:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "FL"."OPR_SERVICE_PROVIDER_CODE"='AI' AND "FL"."OPR_FLIGHT_NUMBER"=1 AND "FL"."OPR_FLIGHT_SUFFIX"='A' AND
    "FL"."HISTORY_VERSION_NUMBER"=0)
    23 - filter("FSFL"."HISTORY_VERSION_NUMBER"=0)
    25 - filter("FS"."HISTORY_VERSION_NUMBER"=0)
    27 - filter("CFL"."HISTORY_VERSION_NUMBER"=0)
    29 - filter("CT"."HISTORY_VERSION_NUMBER"=0)

  • How to insert the select query result into table?

    How to insert the select query result into table?
    SELECT  top 20 creation_time  
            ,last_execution_time 
            ,total_physical_reads
            ,total_logical_reads  
            ,total_logical_writes
            , execution_count 
            , total_worker_time
            , total_elapsed_time 
            , total_elapsed_time / execution_count avg_elapsed_time
            ,SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
             ((CASE statement_end_offset 
              WHEN -1 THEN DATALENGTH(st.text)
              ELSE qs.statement_end_offset END 
                - qs.statement_start_offset)/2) + 1) AS statement_text
    FROM sys.dm_exec_query_stats AS qs
    CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
    ORDER BY total_elapsed_time / execution_count DESC;
    Thanks,
    Tirumala

    1. SELECT INTO
    Below method will create table when data is inserted from one table to another table. Its useful when you need exactly same datatype as source table.
    Use AdventureWorks2008R2;
    Go
    ---Insert data using SELECT INTO
    SELECT AddressLine1, City
    INTO BothellAddresses
    FROM Person.Address
    where City = 'Bothell';
    GO
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    2. INSERT INTO SELECT
    Below method will need table to be created prior to inserting data. Its really useful when table is already created and you want insert data from
    another table.
    Use AdventureWorks2008R2;
    Go
    ---Create Table
    CREATE TABLE BothellAddresses (AddressLine1 NVARCHAR(60), City NVARCHAR(30))
    ---Insert into above table using SELECT
    INSERT INTO BothellAddresses(AddressLine1, City)
    SELECT AddressLine1, City
    FROM Person.Address
    where City = 'Bothell';
    ---VERIFY DATA
    Select AddressLine1, City
    FROM BothellAddresses
    ---DROP TABLE
    DROP TABLE BothellAddresses
    GO
    Regards,
    Vishal Patel
    Blog: http://vspatel.co.uk
    Site: http://lehrity.com

  • How to split this string(char1)char2(char3)char4 into (char1)char2 , .. etc

    how to split this string (char1)char2(char3)char4 into (char1)char2 , (char3)char4?
    String[] result = "(char1)char2(char3)char4".split("\\(");I want :
    result[0] = "(char1)char2" and
    result[0] = "(char3)char4"
    acutally char1,char2,char3, char4 ... is in the form of the below.
    (any charactors except round brace)any charactors except round brace(any charactors except round brace)any charactors except round brace
    I prefer String.split and Pattern.compile().split.
    Edited by: iamjhkang on Feb 5, 2009 3:37 PM
    Edited by: iamjhkang on Feb 5, 2009 3:41 PM

    iamjhkang wrote:
    especially on
    ?= and ?<
    Thanks.The following:
    (?=...)   // positive look ahead
    (?!...)   // negative look ahead
    (?<=...)  // positive look behind
    (?<!...)  // negative look behindare all "look-arounds". See: [http://www.regular-expressions.info/lookaround.html]

  • How to execute a select query stored in variable

    Hello  helpers ,
    I have some "select queries" stored in the database . Now I can derive this query in some variable . How do I execute this query from the variable .
    example :
    Data Query type char50 .
    QueryVar = 'Select MATNR from MBEW where BWKEY = '0001' . '
    How do I execute this Query stoored in variable QueryVar in ABAP program ?
    Thanks a lot for helping .
    Regards
    Shashank

    Shashank,
    It is also possible to use (column_syntax) and (dbtab_syntax) together with (cond_syntax) when using SELECT statements in ABAP. For more info on (column_syntax) and (dbtab_syntax) just have a quick look at ABAP Keyword documention on SELECT statement (hit F1 on SELECT then scroll down to Select->Select result->Select Columns....)
    So in your case, you need to separate out (split) the value in 'wa_itab-query' into other variables or append into separate internal tables using common keys etc. - then looping at those tables with the common key (READ TABLE WITH KEY....) use the following syntax at the time of triggering the SELECT query:
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           WHERE (cond_syntax).
    Also worth a look at this example below:
    PARAMETERS: p_cityfr TYPE spfli-cityfrom,
                p_cityto TYPE spfli-cityto.
    DATA: BEGIN OF wa,
             fldate TYPE sflight-fldate,
             carrname TYPE scarr-carrname,
             connid   TYPE spfli-connid,
           END OF wa.
    DATA itab LIKE SORTED TABLE OF wa
                   WITH UNIQUE KEY fldate carrname connid.
    DATA: column_syntax TYPE string,
          dbtab_syntax TYPE string.
    column_syntax = `c~carrname p~connid f~fldate`.
    dbtab_syntax = `( ( scarr AS c `
      & ` INNER JOIN spfli AS p ON p~carrid  = c~carrid`
      & ` AND p~cityfrom = p_cityfr`
      & ` AND p~cityto   = p_cityto )`
      & ` INNER JOIN sflight AS f ON f~carrid = p~carrid `
      & ` AND f~connid = p~connid )`.
    SELECT (column_syntax)
           FROM (dbtab_syntax)
           INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT itab INTO wa.
      WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Hope this helps.
    Cheers,
    Sougata.

  • How to split this string into 4 sections to a max 35 characters

    Hello,
    Does anyone have an idea how I can acheive this please.
    I have this string
    Expense_Inv_8- ExpenseInv_7- Exp001- Expense_Inv_6- Expense_Inv_5- Expense_Inv_4- Expense_Inv_3- Expense_Inv_2- Expense_inv1
    and I need to display them in sections seperated by ';' as explained below
    Section 1 Section 2 Section 3 Section 4
    Expense_Inv_8- ExpenseInv_7- Exp001;Expense_Inv_6- Expense_Inv_5;Expense_Inv_4- Expense_Inv_3;Expense_Inv_2;
    need to split this string into 4 sections seperated by ';' and each section should be of no more than 35 characters, if null should end ;;;
    Section 1, 35 Character ended by;
    Section 2, broken off after Expense_Inv_5 because Expense_Inv_4 will take it over 35 chracters)
    Section 3, should only take Expense_Inv_4- Expense_Inv_3, because adding Expense_Inv_2 will take it over 35
    characters, each record in the string is seperated by '-'
    Section 4, dispays the reminder of the string
    regards
    Ade

    Hi,
    Welcome to the forum!
    Whenever you ask a question, it helps if you post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) and the results you want from that data.
    I think I understand the problemk well enough to attempt a solution, but if the query below isn't right, please post that information.
    WITH     cntr     AS
         SELECT     LEVEL     AS n
         FROM     dual
         CONNECT BY     LEVEL     <= ( SELECT  MAX (LENGTH (txt))
                             FROM    table_x
    ,     got_best_path     AS
         SELECT     id
         ,     txt
         ,     MAX ( SYS_CONNECT_BY_PATH ( TO_CHAR (c.n, '99')
                      ) AS best_path
         FROM     cntr     c
         JOIN     table_x     x     ON     c.n <= LENGTH (x.txt)
         START WITH     c.n     = 1
         CONNECT BY     c.n - PRIOR c.n     BETWEEN  1
                                 AND      :section_length
              AND     x.id          = PRIOR     x.id
              AND     SUBSTR ( x.txt
                                 , c.n
                                 , 1
                                 )     = '-'
         AND     LEVEL          <= :section_cnt
         GROUP BY  id
         ,            txt
    ,     got_pos     AS
         SELECT     id
         ,     REPLACE ( txt
                   ) || ';'                         AS txt
         ,     best_path
         ,     TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 2))     AS pos_2
         ,     TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 3))     AS pos_3
         ,     TO_NUMBER (REGEXP_SUBSTR (best_path, '[0-9]+', 1, 4))     AS pos_4
         FROM     got_best_path
    SELECT  id
    ,     SUBSTR (txt,     1    , NVL ( pos_2         , :section_length))     AS section_1
    ,     SUBSTR (txt, pos_2 + 1, NVL ((pos_3 - pos_2), :section_length))     AS section_2
    ,     SUBSTR (txt, pos_3 + 1, NVL ((pos_4 - pos_3), :section_length))     AS section_3
    ,     SUBSTR (txt, pos_4 + 1,                        :section_length )     AS section_4
    FROM     got_pos
    ;As written, this requires SQL*Plus 9 (or higher). You can have multiple versions or SQL*Plus on the same client, if you really need to keep the older version.
    :section_length is the maximum length of each section (35, as you stated the problem).
    :section_cnt is the number of sections. In the query above, this is 4. If you change it, you not only have to change the bind variable, but you have to change the hard-coded SELECT clauses of the main query and the last sub-query (that is, got_pos).
    MODEL or PL/SQL would probably be better ways to solve this problem.

  • How to write this sql query in php code ?

    for example:
    insert into temp
    select *
    from testtable;
    after this, i will query data from sql below:
    select *
    from temp;
    how to write this php code ?
    who can help me ?
    thanks!

    Have a look at the manual to find out how to issue queries.
    http://us3.php.net/oci8

Maybe you are looking for

  • Who can give me a clear picture on getCalllerPrincipal in EJB

    We keep on encountering some problems which are related with security issues. So I hope can get a clear picture on how it is handled inside WebLogic. Currently what we did is we create a common login function. Inside this function, we declare a local

  • Logs are empty

    Hi to all I have Nokia N72 model. I am facing one problem in my cell. It dosen't show the logs. All the dialed, received and missed calls are empty. Anyone can help me to resolve this problem. Thanx in Advance Niraj

  • Pesonlization in CRMD_ORDER

    Hi gurus Does anybody know how to apply personalization in CRMD_ORDER to all users? (Personalization object CRM_ONEORDER) I want to uncheck "Open last transaction processed" and set "minimized" as defult setting for all users. But It seems that I nee

  • Recon and provisioning of user-defined object class ICF Active Directory

    I have followed the documentation instructions for reconciliation of a user-defined object class in the ICF Active Directory connector. I am using OIM 11gR2 with the ICF Active Directory 11.1.1.5 connector patched to 11.1.1.5.0A. The procedure states

  • How to extract code from text box in html format

    "I have a text box. When the form is submitted I need to extract the data in html format. i.e. a string type variable needds to hold all html tags alongwith[b] the data."