Need to merge the query's

Hi,
Ii need to merge the below 2 queries.could you please help some one.
primary foreign key relation of major_id column
major.major_id primary key.
major_inactive_list.major_id referential integrity
SELECT   m.major_inactive_id, m.institution_id, m.major_id, m.created_on,
         m.modified_on, m.created_by, m.modified_by, m.active_status
    FROM major_inactive_list m
   WHERE m.institution_id IN (1, 5)
ORDER BY m.institution_id
SELECT   M.major_id ,
                 M.major_name ,
                 M.major_code ,
                 M.major_comment,
                 M.delete_status,
                 M.active_status,
                 M.institution_id,
                 M.default_major
            FROM major M
           WHERE     (M.institution_id IN (1, 5, 6))
                 AND M.delete_status = '0'
                 AND M.active_status = '1'
                 AND (M.major_id NOT IN (768002, 767978))
              OR     M.institution_id = 6
                 AND M.active_status = '0'
                 AND M.delete_status = '0'
        ORDER BY M.institution_id DESC, UPPER (M.major_name)

need to re write as a single query instead of 2 queries.There should be some logic behind making it as a single query. I was looking for you to explain that. If you ask me to make it a single query without giving any details i would do this.
with t1
as
SELECT m.major_inactive_id, m.institution_id, m.major_id, m.created_on,
       m.modified_on, m.created_by, m.modified_by, m.active_status
  FROM major_inactive_list m
WHERE m.institution_id IN (1, 5)
t2 as
SELECT M.major_id ,
       M.major_name ,
       M.major_code ,
       M.major_comment,
       M.delete_status,
       M.active_status,
       M.institution_id,
       M.default_major
  FROM major M
WHERE M.institution_id IN (1, 5, 6)
   AND M.delete_status = '0'
   AND M.active_status = '1'
   AND M.major_id NOT IN (768002, 767978)
    OR M.institution_id = 6
   AND M.active_status = '0'
   AND M.delete_status = '0'
select t1.*, t2.*
  from t1, t2
where t1.major_id = t2.major_id

Similar Messages

  • Need to merge the below two rows

    Hi,
    I have a sample data as shown below:
    ID     OBJID     ACT_CODE     ADDNL_INFO     ENTRY_TIME
    2523540     333003736     900     from WIP default to Queue PSD1.     1/3/2012 15:07
    2523540     333003271     100     100 from Queue PSD1 to WIP For assigment. 1/3/2012 15:43
    2523540     333003744     900     900 from WIP default to Queue PSD1.     1/3/2012 15:49
    2523540     333004966     100     100 from Queue PSD1 to WIP For assigment.     1/3/2012 16:04
    I need to merge the first two rows and get a single record for each "from" and "to" as shown below (desired output)
    ID_NUMBER     ADDNL_INFO     ENTRY_TIME     EXIT_TIME     TOTAL TIME
    2523540     PSD1     1/3/2012 15:07     1/3/2012 15:43     0.025069444
    2523540     PSD1     1/3/2012 15:49     1/3/2012 16:04     0.010231481
    I have used function on the addnl_info column to display only the name of the queue "PSD1"
    (SUBSTR(ADDNL_INFO, INSTR(ADDNL_INFO, 'PSD1'), LENGTH('PSD1'))) QUEUE_NAME
    Can any one help me out in getting the desired output.

    Below is a solution to your query:
    drop table test_Table;
    create table test_Table
      ID          number,
      objid       number,
      act_code    number,
      addl_info   varchar2(500),
      entry_time  timestamp
    insert into test_Table values (2523540, 333003736, 900, 'from WIP default to Queue PSD1.', to_timestamp('1/3/2012 15:07', 'DD/MM/YYYY HH24:MI'));
    insert into test_Table values (2523540, 333003271, 100, 'from Queue PSD1 to WIP For assigment.', to_timestamp('1/3/2012 15:43', 'DD/MM/YYYY HH24:MI'));
    insert into test_Table values (2523540, 333003744, 900, 'from WIP default to Queue PSD1.', to_timestamp('1/3/2012 15:49', 'DD/MM/YYYY HH24:MI'));
    insert into test_Table values (2523540, 333004966, 100, 'from Queue PSD1 to WIP For assigment.', to_timestamp('1/3/2012 16:04', 'DD/MM/YYYY HH24:MI'));
    select * from test_table;
    select id, addl_info, entry_time, exit_time, total_time
    from
    select a.id, a.objid, 'PSD1' addl_info, a.entry_time, lead(a.entry_time, 1, null) over (order by a.entry_time) exit_time,
           lead(a.entry_time, 1, null) over (order by a.entry_time) - a.entry_time total_time, DECODE(a.act_code, 900, 'D', 'ND') disp
      from test_Table a
    where a.id = 2523540
    where disp = 'D';
    ID             ADDL_INFO            ENTRY_TIME          EXIT_TIME                     TOTAL_TIME
    2523540     PSD1     01-MAR-12 03.07.00.000000000 PM     01-MAR-12 03.43.00.000000000 PM     0 0:36:0.0
    2523540     PSD1     01-MAR-12 03.49.00.000000000 PM     01-MAR-12 04.04.00.000000000 PM     0 0:15:0.0I see a shortcoming in the design:
    1. For "WIP default to Queue PSD1" there are two records, both containing different OBJID but same ID, which in ideal case should not happen. You MUST have a COMPOSITE key on ID and OBJID; This shall help you to identify the distinct records.
    My solution is not perfect as it is based on the ENTRY TIME. The reason being SIMPLE Ordering by the OBJID would not lead to a correct difference in the Transaction Time (referred by you as TOTAL_TIME.); Hence, for this reason I had to use ENTRY_TIME to correctly get the total_time.
    If you wish you may follow the solution else I shall always recommend to change the Table Design and follow the correct approach.
    If you are changing the Table design then following shall be a solution:
    select id, addl_info, entry_time, exit_time, total_time
    from
    select a.id, a.objid, 'PSD1' addl_info, a.entry_time, lead(a.entry_time, 1, null) over (order by a.id, a.objid) exit_time,
           lead(a.entry_time, 1, null) over (order by a.entry_time) - a.entry_time total_time, DECODE(a.act_code, 900, 'D', 'ND') disp
      from test_Table a
    where disp = 'D';Regards,
    P.

  • Help needed to optimize the query

    Help needed to optimize the query:
    The requirement is to select the record with max eff_date from HIST_TBL and that max eff_date should be > = '01-Jan-2007'.
    This is having high cost and taking around 15mins to execute.
    Can anyone help to fine-tune this??
       SELECT c.H_SEC,
                    c.S_PAID,
                    c.H_PAID,
                    table_c.EFF_DATE
       FROM    MTCH_TBL c
                    LEFT OUTER JOIN
                       (SELECT b.SEC_ALIAS,
                               b.EFF_DATE,
                               b.INSTANCE
                          FROM HIST_TBL b
                         WHERE b.EFF_DATE =
                                  (SELECT MAX (b2.EFF_DATE)
                                     FROM HIST_TBL b2
                                    WHERE b.SEC_ALIAS = b2.SEC_ALIAS
                                          AND b.INSTANCE =
                                                 b2.INSTANCE
                                          AND b2.EFF_DATE >= '01-Jan-2007')
                               OR b.EFF_DATE IS NULL) table_c
                    ON  table_c.SEC_ALIAS=c.H_SEC
                       AND table_c.INSTANCE = 100;

    To start with, I would avoid scanning HIST_TBL twice.
    Try this
    select c.h_sec
         , c.s_paid
         , c.h_paid
         , table_c.eff_date
      from mtch_tbl c
      left
      join (
              select sec_alias
                   , eff_date
                   , instance
                from (
                        select sec_alias
                             , eff_date
                             , instance
                             , max(eff_date) over(partition by sec_alias, instance) max_eff_date
                          from hist_tbl b
                         where eff_date >= to_date('01-jan-2007', 'dd-mon-yyyy')
                            or eff_date is null
               where eff_date = max_eff_date
                  or eff_date is null
           ) table_c
        on table_c.sec_alias = c.h_sec
       and table_c.instance  = 100;

  • Need to save the query under the correct role

    Hi Experts,
    I need to save the query under the specific role. So is there anyway to find the query location by role??
    Thanks
    Regards,
    Arpan

    Hi,
    RSZCOMPDIR --> RSRREPDIR -->AGR_HIER
    From RSZCOMPDIR get all the entries of queries.
    compid is query name, take compuID and pass to RSRREPDIR.
    get genuniid and pass to AGR_HIER's sap_guid.
    AGR_NAME in AGR_HIER is role name.
    please check this.
    -Sriram
    Message was edited by: Sriramvijay R
    Message was edited by: Sriramvijay R

  • Needs to tune the query

    Hi ,
    I have a Query that needs to be tuned.
    The query joins two views with some filter condition.
    While running the individual view query with the filter condition i can able to get the results quickly within a seconds.
    But while joining the views conditions of the same criteria which i have used for the individual query takes more than 30 minute.
    i am struggling to tuning this query which was written using the views.
    Note :
    My problem is while checking the explain plan unique sort is taking more cost.
    is that i can reduce the time by giving some optimizer hints to reduce the unique sort cost for query using views?
    Thanks & regards,
    Senthur pandi M

    Hi,
    BluShadow wrote:
    957595 wrote:
    Hi ,
    I have a Query that needs to be tuned.
    The query joins two views with some filter condition.
    While running the individual view query with the filter condition i can able to get the results quickly within a seconds.
    But while joining the views conditions of the same criteria which i have used for the individual query takes more than 30 minute.
    i am struggling to tuning this query which was written using the views.
    Note :
    My problem is while checking the explain plan unique sort is taking more cost.Cost in not necessarily a good comparison to use. The cost is a figure determined on a per-query basis,The problem with cost is that it's a prediction made by the optimizer, rather than the actual measure of query performance. Optimizer often makes mistakes about expected query performance. Ironically, people normally look at query cost when it needs tuning, i.e. when the chance that optimizer made a mistake is especially high.
    In many internet forums one can see claims that cost estimates are meaningless across different queries. Such claims are unfounded. When calculated correctly, cost is quite meaningful, and in such cases there is nothing wrong about comparing cost not only for different queries, but also for different databases (if they have same optimizer settings and system stats).
    is that i can reduce the time by giving some optimizer hints to reduce the unique sort cost for query using views?Hints are not the way to improve performance. That's an overstatement. The sad truth is that in many cases there is no viable alternative to using hints. Rather than always avoid hints no matter what cost, it's better to understand how hints affect optimizer behavior, and when it's safe to use them.
    They are great for identifying where the cause of a performance issue is, but shouldn't be used in production code, as it would be like saying that you know better than Oracle how to retrieve the data, not just now, but in the future as more
    data is added and as data is deleted and replaced with new data etc. By adding hints you are effectively forcing the optimizer to execute the query in a particular way, which may be fast now, but in the future may be worse than what the optimizer can determine itself.Hints that force the optimizer to use a specific access path or a specific join method are dangerous -- because the only lock-in one part of the plan, but not the entire plan (e.g. INDEX hint only ensures that an index is used if possible, but it cannot ensure INDEX UNIQUE/RANGE SCAN, so you may end up in a situation when the optimizer is doing an expensive and meaningless INDEX FULL SCAN because of the hint that was indended to force a different, more selective, access method).
    Hints that don't do that, but rather prevent the optimizer from trying to be smart when it's better to keep things simple, are relatively safe.
    So, use the hints to identify where there are issues in the SQL or in the database design, and fix those issues, rather than leave hints in production code.As a general rule, sure. Here, however, the problem seems to be obvious -- if views are fast separately, and slow when joined, that suggests that the optimizer doesn't merge them correctly.
    Best regards,
    Nikolay

  • Help needed to tune the Query:Statistics added

    Can someone DBA please help me to tune this query:
    SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
    CASE
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    ELSE
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
    FROM
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN ('%')
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
    AND NVL(G.OFFICE_ID,0) IN ('%')
    AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
    ORDER BY PROFILE_NM
    The number of rows in these tables are as follows:
    PROFILE_PORTAL -- 2392
    TBL_BDA_AGENCY_RESP_REP 3508
    TBL_BDA_AGENCY_OFFICE 2151
    TBL_BDA_OFFICE 3
    USERS_PORTAL 270500
    TBL_BDA_USR_ISS_GRP 234
    TBL_BDA_ISS_GROUP 2
    ATTRIBUTE_VALUES_PORTAL 2790
    PROFILE_TYPE_PORTAL 3
    The Explain pal nhas given this o/p to me:
    SQL> select * from table(dbms_xplan.display) dual;
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
    | 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
    | 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
    |* 2 | FILTER | | | | | |
    |* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
    |* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
    |* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
    | 6 | NESTED LOOPS | | 7 | 805 | | 37 |
    | 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
    |* 8 | FILTER | | | | | |
    | 9 | NESTED LOOPS OUTER | | | | | |
    |* 10 | FILTER | | | | | |
    | 11 | NESTED LOOPS OUTER | | | | | |
    | 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
    |* 13 | HASH JOIN | | 3 | 120 | | 7 |
    |* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
    |* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
    |* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
    | 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
    |* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
    | 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
    |* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    | 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
    |* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
    |* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
    | 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
    | 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
    |* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
    |* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    Predicate Information (identified by operation id):
    2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
    AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
    3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
    4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
    5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
    8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
    10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
    13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
    14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
    NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
    15 - filter("L"."APPLICATION_CD"='BDA')
    16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
    18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
    20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
    22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
    23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
    26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
    27 - access("T"."AGENCY_ID"=:B1)
    Note: cpu costing is off
    57 rows selected.
    Elapsed: 00:00:01.08
    Please help me.
    Aashish S.

    Hello Eric,
    Here is the code:
    SELECT DISTINCT
    K.ATTRIBUTE_VALUE AGENCY_ID,
    B.PROFILE_NM ,
    NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
    f.OFFICE_ID,
    B.PROFILE_ID,
    '%' ROLE,
    '%' LAYOUT,
    case
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    else
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','&lt;a sbcuid_in=' || H.USERID || ' target=NEW &gt;'||H.FIRSTNAME || ' ' || H.LASTNAME ||
    '( ' || H.USERID || ' )&lt;/a&gt;' ) USER_NAME
    from
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS
    (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN (1)
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0))
    LIKE '%'
    OR NVL(B.PROFILE_ID,0) IN (1))
    AND NVL(G.OFFICE_ID,0) IN (1)
    AND (to_char(NVL(C.RESP_USR_ID,'0'))
    LIKE '%'
    OR NVL(C.RESP_USR_ID,'0') IN ('%'))
    ORDER BY PROFILE_NM
    This is the Query and the query takes some mins. to run in prod environment.
    From the Query plan ,I am not able to get any idea for optimization.
    Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
    Thanks.
    Aashish S.

  • Need to optimise the query....

    Hi experts, the following query takes 2.5 hrs to execute. I went through other forums to optimise it, but couldnt understand. Anyone can split the query to optimise it please.
    select aebeln bebelp alponr alifnr awaers abedat
    aknumv btxz01 bnetpr bwerks b~aedat
    bmatkl bmatnr clfbnr clfpos cpackno csrvpos
    cbelnr cbuzei cdmbtr cwrbtr c~waers
    cshkzg cbudat d~eindt
    into table it_ekko
    from ekko as a inner join ekpo as b
    on aebeln = bebeln
    inner join ekbe as c
    on aebeln = cebeln and
    bebeln = cebeln and
    bebelp = cebelp
    inner join eket as d
    on aebeln = debeln and
    bebeln = debeln and
    bebelp = debelp and
    cebeln = debeln and
    cebelp = debelp
    for all entries in it_eket
    where
    ( a~ebeln = it_eket-ebeln and
    b~ebeln = it_eket-ebeln and
    b~ebelp = it_eket-ebelp and
    c~ebeln = it_eket-ebeln and
    c~ebelp = it_eket-ebelp and
    d~eindt = it_eket-eindt ) and
    a~bsart = 'ZSFG' and
    d~eindt in l_r_date2 and
    c~vgabe = '1'.
    Thanks,
    Taj

    HI vikranth,
    thanks for the detailed code. But i have one doubt. In the last select statement do we need to add in where condition
    ebeln = it_ekbe-ebeln and
    ebelp = it_ekbe-ebelp      (  for  cebeln = debeln and
    cebelp = debelp ,   of my original code ) .
    And another thing is dat in last select statement "for all entries in it_eket" or "for all entries in it_ekeb" should be thr.
    And i want all of these records to be in one final internal table.
    I have provided the full code below.
    **&      Form  Data_ekko_ekpo1
          text
    -->  p1        text
    <--  p2        text
    *form data_ekko_ekpo1 tables l_r_budat1 like l_r_date.
    select ebeln ebelp eindt
    into table it_eket
    from eket
    where eindt eq l_r_budat1.
    *if not it_eket[] is initial.
    select aebeln bebelp alponr alifnr awaers abedat
            aknumv btxz01 bnetpr bwerks b~aedat
            bmatkl bmatnr clfbnr clfpos cpackno csrvpos
            cbelnr cbuzei cdmbtr cwrbtr c~waers
            cshkzg cbudat d~eindt
    into table it_ekko
    from ekko as a inner join ekpo as b
    on aebeln = bebeln
    inner join ekbe as c
    on aebeln = cebeln and
        bebeln = cebeln and
        bebelp = cebelp
    inner join ekeT as d
    on aebeln = debeln and
        bebeln = debeln and
        bebelp = debelp and
        cebeln = debeln and
        cebelp = debelp
    for all entries in it_eket
    where
        ( a~ebeln  = it_eket-ebeln and
          b~ebeln  = it_eket-ebeln and
          b~ebelp  = it_eket-ebelp and
          c~ebeln  = it_eket-ebeln and
          c~ebelp  = it_eket-ebelp and
          d~eindt  = it_eket-eindt ) and
          a~lifnr in s_lifnr1 and  " Vendor
          a~bsart = 'ZSFG'   and  " Doc Type
          b~werks in s_werks2 and  " Plant
          d~eindt  eq l_r_budat1 and  " Posting Date
          c~vgabe = '1'.          " Service Ent Sht
    *it_ekko_h[] = it_ekko[].
    *delete it_ekko_h where shkzg <> 'H'.
    *it_ekko_s[] = it_ekko[].
    *delete it_ekko_s where shkzg <> 'S'.
    *sort it_ekko by ebeln ebelp dmbtr shkzg .
    *sort it_ekko_h by ebeln ebelp dmbtr shkzg .
    *loop at it_ekko_h.
    loop at it_ekko where ebeln = it_ekko_h-ebeln
                       and ebelp = it_ekko_h-ebelp
                       and dmbtr = it_ekko_h-dmbtr
                       and shkzg = 'S'.
       delete it_ekko.
       exit.
    endloop.
    clear it_ekko_h.
    *endloop.
    *delete it_ekko where shkzg = 'H' .
    *endif.
    *endform.                    " Data_ekko_ekpo1
    Thanks

  • Help needed in generating the query

    Hi All,
    While fetching the required columns from the table, i also have to display the seq no starting with some no. ( which will vary based on the functionality, so it ll be a sep variable.) and will get incremented with a offset value.
    Current code:
    select col1, col2, col3 from table1 where col1 = valid_condition; Expected code / Or approach:
    select start_val+offset_val , col1, col2, col3 from table1 where col1 = valid_condition; This select query is part of a view and the values for start_val, offset_val will be set as global params.
    Is there any easier way of implementing this in the query, other than creating a seq no.
    thanks in advance.

    Hi,
    This sounds like a job for ROWNUM or ROW_NUMBER.
    The ROWNUM pseudo-column is easy to use, but the numbers aren't necessarily assigned in the order you'd like:
    SELECT       ename
    ,       1000 + ROWNUM          AS seq_no
    FROM       scott.emp
    WHERE       deptno     = 30
    ORDER BY  ename
    ;Output:
    ENAME          SEQ_NO
    ALLEN            1001
    BLAKE            1004
    JAMES            1006
    MARTIN           1003
    TURNER           1005
    WARD             1002To assign the numbers in order, you could select ROWNUM from an ordered sub-query (or view), but if you're going to that much trouble, you might as well use the analytic ROW_NUMBER function:
    SELECT       ename
    ,       1000 + ROW_NUMBER () OVER (ORDER BY ename)          AS seq_no
    FROM       scott.emp
    WHERE       deptno     = 30
    ORDER BY  ename
    ;Output:
    ENAME          SEQ_NO
    ALLEN            1001
    BLAKE            1002
    JAMES            1003
    MARTIN           1004
    TURNER           1005
    WARD             1006Edited by: Frank Kulash on Nov 25, 2009 1:32 PM

  • Need solution for the query

    hi All,
    I have 3 tables 1)PREVILEGES (groupname, previleges(values y or n only))
    2)GROUPS (groupid, groupname)
    3) USERS (uname, groupname).
    Here each user belongs to one group, each user hav a default previlege means example if user is consutant then he can access only consultant group. Means default previlege will be used. For default previleges, there is no record in Previleges table.
    The Problem is that, I need to reterive the groupname from users which de doesn't belong as well as his previleges from previleges, If there is no values in previleges in the table it should return n. or value what is therey.
    the different groups are
    SALES,CONSULTANT,VENDER,RECRUTER,ADMIN

    [url http://forums.oracle.com/forums/thread.jspa?threadID=491856&tstart=0]duplicate thread

  • Needs help for the query

    Hi All,
    I had atable containing 2 columns like NO and Grade.
    ID Grade DEPTID
    1 A 10
    2 E 20
    3 D 20
    4 C 30
    5 H 10
    6 K 10
    7 B 30
    8 L 30
    9 R 20
    i need output as
    DEPTID Employees and grades in the DEPT
    10 1 A , 5 H , 6 K
    20 2 E , 3 D , 9 R
    30 4 C , 7 B , 8 L
    Please anyone give me query for this.
    thanks in advance.
    rampa

    STRAGG for string aggregation. One of the most frequent ask question over here.
    Here a forum search for you.
    Of course, the options depend of version you are on.
    Nicolas.

  • I need to merge the contacts between my MAC and iPhone 4  ... Tried many ways ...

    i have 50 contacts on my Macbook air and 350 on my iphone , i need to know how to merge them , iTunes is not syncing the contacts at all even when i choose the option to sync , i tried many ways !! apparently there is only an option to replace whats on the iPhone by the computer's contact but not the opposite . please help ...

    With the iPhone connected have you checked Address Book as the app to sync to on the Info tab? If you have then go to the iSync app Preferences, and click Reset Sync History.

  • Need to modify the query

    Hi All,
    I am a new DBA. Please help me in modifying the below query in test envirnoment. It is long query.
    SELECT NVL(MIN(P_LAY),0), NVL(MIN(TID),0), NVL(MIN(TTIME),0), NVL(MIN(TSOURCE),0) FROM ( SELECT P_LAY, TID, TTIME, TSOURCE FROM ( SELECT (CASE WHEN T1.INTERNAL_TYPE=3 THEN -1 ELSE T_REPORT.GET_LAY(T1.EVE_ID, T1.EVE_TIME,:B4 ) END ) P_LAY, T1.EVE_ID TID, T1.EVE_TIME TTIME, T1.ALA_SOURCE_ID TSOURCE FROM T_EVE_LOG T1, T_EVE_LOG T2 WHERE T1.ALA_ID = T2.ROOT_ALA_ID AND T2.EVE_TIME >= :B3 AND T2.EVE_TIME < :B2 AND T2.ALA_ID = :B1 AND T2.ACT_ID IN (2,5) ) ORDER BY P_LAY ) WHERE ROWNUM = 1
    Thanks in Advance

    886755 wrote:
    Hi All,
    I am a new DBA. Please help me in modifying the below query in test envirnoment. It is long query.
    SELECT NVL(MIN(P_LAY),0), NVL(MIN(TID),0), NVL(MIN(TTIME),0), NVL(MIN(TSOURCE),0) FROM ( SELECT P_LAY, TID, TTIME, TSOURCE FROM ( SELECT (CASE WHEN T1.INTERNAL_TYPE=3 THEN -1 ELSE T_REPORT.GET_LAY(T1.EVE_ID, T1.EVE_TIME,:B4 ) END ) P_LAY, T1.EVE_ID TID, T1.EVE_TIME TTIME, T1.ALA_SOURCE_ID TSOURCE FROM T_EVE_LOG T1, T_EVE_LOG T2 WHERE T1.ALA_ID = T2.ROOT_ALA_ID AND T2.EVE_TIME >= :B3 AND T2.EVE_TIME < :B2 AND T2.ALA_ID = :B1 AND T2.ACT_ID IN (2,5) ) ORDER BY P_LAY ) WHERE ROWNUM = 1
    Thanks in Advancemodify it how to do what?
    SELECT Nvl(MIN(p_lay), 0),
           Nvl(MIN(tid), 0),
           Nvl(MIN(ttime), 0),
           Nvl(MIN(tsource), 0)
    FROM   (SELECT p_lay,
                   tid,
                   ttime,
                   tsource
            FROM   (SELECT ( CASE
                               WHEN t1.internal_type = 3 THEN -1
                               ELSE t_report.Get_lay(t1.eve_id, t1.eve_time, :B4)
                             END )          p_lay,
                           t1.eve_id        tid,
                           t1.eve_time      ttime,
                           t1.ala_source_id tsource
                    FROM   t_eve_log t1,
                           t_eve_log t2
                    WHERE  t1.ala_id = t2.root_ala_id
                           AND t2.eve_time >= :B3
                           AND t2.eve_time < :B2
                           AND t2.ala_id = :B1
                           AND t2.act_id IN ( 2, 5 ))
            ORDER  BY p_lay)
    WHERE  ROWNUM = 1 

  • Need help with the query -

    We have these two tables and trying to see if the amount in one table is equal to the sum of the amount fields in another table.
    Can someone please help?
    SQL> desc test;
    Name Null? Type
    KEY NUMBER(9)
    AMOUNT NUMBER(11,2)
    SQL> desc test1;
    Name Null? Type
    KEY NUMBER(9)
    TOTAL_AMOUNT NUMBER(11,2)
    SQL> select * from test;
    KEY AMOUNT
    1 10
    1 20
    1 70
    3 rows selected.
    SQL> select * from test1;
    KEY TOTAL_AMOUNT
    1 100
    1 row selected.
    SQL> select count(*) from test1 a where exists(select 'x' from test b where
    2 a.key=b.key and a.total_amount!=sum(b.amount));
    a.key=b.key and a.total_amount!=sum(b.amount))
    ERROR at line 2:
    ORA-00934: group function is not allowed here

    Hi,
    This would be so easy if there was a table like test that only had one row per key!
    You can make such a table, or you can just make a sub-query that has all the same data, and use that sub-query as if it were a table.
    For example:
    WITH  one_row_per_key_test  AS
        SELECT    key
        ,         SUM (amount)  AS total_amount
        FROM      test
        GROUP BY  key
    SELECT  COUNT (*)
    FROM    test1   a
    WHERE   EXISTS
            SELECT  'x'
            FROM    one_row_per_key_test  b
            WHERE   a.key          = b.key
            AND     a.total_amount = b.total_amount
            );There are lots of other ways to solve this particular problem (including HAVING), but this is a very important technique to know.

  • Need help in the Query

    I am trying to build a query with
    1)Customer name,Account number and monthly revenue.
    2) Customer name, Year-to -date revenue.
    I dont know which tables should i join to get the results.

    I dont know which tables should i join to get the results. Neither do we ;-).
    Without any details, no one will be able to help you.

  • Merge the Query

    SELECT
    MAX(fndattdoc.LAST_UPDATE_DATE ) as LAST_UPDATE_DATE,
    MAX(DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL)) as COMMENTS,
    MAX(fnddoc.description) as REASON
    FROM fnd_attachment_functions fndattfn,
    fnd_doc_category_usages fndcatusg,
    fnd_documents_vl fnddoc,
    fnd_attached_documents fndattdoc,
    fnd_documents_short_text st,
    fnd_document_categories_tl fl,
    WSH_NEW_DELIVERIES DLVRY
    WHERE fndattfn.attachment_function_id = fndcatusg.attachment_function_id
    AND fndcatusg.category_id = fnddoc.category_id
    AND fnddoc.document_id = fndattdoc.document_id
    AND fndattfn.function_name = 'WSHFSTRX'
    AND fndattdoc.entity_name = 'WSH_NEW_DELIVERIES'
    AND fl.CATEGORY_ID = fnddoc.category_id
    AND fl.LANGUAGE = 'US'
    AND fl.USER_NAME ='Delivery Failure'
    AND fndattdoc.pk1_value =DLVRY.DELIVERY_ID
    AND FNDDOC.DESCRIPTION NOT IN ('Corrected Actual Delivery Date','Corrected Promised Date')
    AND fnddoc.media_id=st.media_id
    GROUP BY fndattdoc.pk1_value
    SELECT
    MAX(DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL)) as CORRECTD_ACTUAL_DELIVERY_DATE,
    MAX(fndattdoc.LAST_UPDATE_DATE ) as LAST_UPDATE_DATE
    FROM fnd_attachment_functions fndattfn,
    fnd_doc_category_usages fndcatusg,
    fnd_documents_vl fnddoc,
    fnd_attached_documents fndattdoc,
    fnd_documents_short_text st,
    fnd_document_categories_tl fl,
    WSH_NEW_DELIVERIES DLVRY
    WHERE fndattfn.attachment_function_id = fndcatusg.attachment_function_id
    AND fndcatusg.category_id = fnddoc.category_id
    AND fnddoc.document_id = fndattdoc.document_id
    AND fndattfn.function_name = 'WSHFSTRX'
    AND fndattdoc.entity_name = 'WSH_NEW_DELIVERIES'
    AND fl.CATEGORY_ID = fnddoc.category_id
    AND fl.LANGUAGE = 'US'
    AND fl.USER_NAME ='Delivery Failure'
    AND fndattdoc.pk1_value =DLVRY.DELIVERY_ID
    AND FNDDOC.DESCRIPTION = 'Corrected Actual Delivery Date'
    AND fnddoc.media_id=st.media_id
    GROUP BY fndattdoc.pk1_value
    SELECT
    MAX(DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL) ) AS CORRECTD_PROMISE_DATE,
    MAX(fndattdoc.LAST_UPDATE_DATE ) as LAST_UPDATE_DATE
    FROM fnd_attachment_functions fndattfn,
    fnd_doc_category_usages fndcatusg,
    fnd_documents_vl fnddoc,
    fnd_attached_documents fndattdoc,
    fnd_documents_short_text st,
    fnd_document_categories_tl fl,
    WSH_NEW_DELIVERIES DLVRY
    WHERE fndattfn.attachment_function_id = fndcatusg.attachment_function_id
    AND fndcatusg.category_id = fnddoc.category_id
    AND fnddoc.document_id = fndattdoc.document_id
    AND fndattfn.function_name = 'WSHFSTRX'
    AND fndattdoc.entity_name = 'WSH_NEW_DELIVERIES'
    AND fl.CATEGORY_ID = fnddoc.category_id
    AND fl.LANGUAGE = 'US'
    AND fl.USER_NAME ='Delivery Failure'
    AND fndattdoc.pk1_value =DLVRY.DELIVERY_ID
    AND FNDDOC.DESCRIPTION = 'Corrected Promised Date'
    AND fnddoc.media_id=st.media_id
    GROUP BY fndattdoc.pk1_value
    Hi I have above three select stetements, I have to merge those select statements into one select statements, all select statements having same conditions and filter conditions(in each select statement one filter condition different), I highlighted in the bold differencet filter conditions in each table, fianlly I should be get 7 coloumns like
    LAST_UPDATE_DATE, COMMENTS, REASON, CORRECTD_ACTUAL_DELIVERY_DATE, LAST_UPDATE_DATE, CORRECTD_PROMISE_DATE, LAST_UPDATE_DATE
    Please help on this
    Thanks
    Venki

    Use CASE?
    Possibly something like this:
    SELECT
    MAX(CASE WHEN FNDDOC.DESCRIPTION NOT IN ('Corrected Actual Delivery Date','Corrected Promised Date')
             THEN fndattdoc.LAST_UPDATE_DATE
        END) as LAST_UPDATE_DATE,
    MAX(CASE WHEN FNDDOC.DESCRIPTION NOT IN ('Corrected Actual Delivery Date','Corrected Promised Date')
             THEN DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL)
        END) as COMMENTS,
    MAX(CASE WHEN FNDDOC.DESCRIPTION NOT IN ('Corrected Actual Delivery Date','Corrected Promised Date')
             THEN fnddoc.description
        END) as REASON,
    MAX(CASE WHEN FNDDOC.DESCRIPTION = 'Corrected Actual Delivery Date'
             THEN DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL)
        END) as CORRECTD_ACTUAL_DELIVERY_DATE,
    MAX(CASE WHEN FNDDOC.DESCRIPTION = 'Corrected Actual Delivery Date'
             THEN fndattdoc.LAST_UPDATE_DATE
        END) as LAST_UPDATE_DATE,
    MAX(CASE WHEN FNDDOC.DESCRIPTION = 'Corrected Promised Date'
             THEN DECODE(fndcatusg.format,'H', st.short_text,NULL,st.short_text, NULL)
        END) AS CORRECTD_PROMISE_DATE,
    MAX(CASE WHEN FNDDOC.DESCRIPTION = 'Corrected Promised Date'
             THEN fndattdoc.LAST_UPDATE_DATE
        END) as LAST_UPDATE_DATE
    FROM fnd_attachment_functions fndattfn,
    fnd_doc_category_usages fndcatusg,
    fnd_documents_vl fnddoc,
    fnd_attached_documents fndattdoc,
    fnd_documents_short_text st,
    fnd_document_categories_tl fl,
    WSH_NEW_DELIVERIES DLVRY
    WHERE fndattfn.attachment_function_id = fndcatusg.attachment_function_id
    AND fndcatusg.category_id = fnddoc.category_id
    AND fnddoc.document_id = fndattdoc.document_id
    AND fndattfn.function_name = 'WSHFSTRX'
    AND fndattdoc.entity_name = 'WSH_NEW_DELIVERIES'
    AND fl.CATEGORY_ID = fnddoc.category_id
    AND fl.LANGUAGE = 'US'
    AND fl.USER_NAME ='Delivery Failure'
    AND fndattdoc.pk1_value =DLVRY.DELIVERY_ID
    AND fnddoc.media_id=st.media_id
    GROUP BY fndattdoc.pk1_value

Maybe you are looking for

  • Zipping the payload using File adapter

    Hi Experts, I have a 620 MB xml file, which need to be archived on daily basis. but the XI server shows 503 service unavailable message, while trying to process the huge file. also used the Zippayloadbean module in the file adapter, but no luck. Plea

  • How to hide a Column

    Gurus Using XSL FO how can i hide a column based upon a value in XML file.Can you please guide Regards Nitin

  • User exit to enhance PR creation from work order

    Hi Experts, When creating a work order, we can also automatically create PR (Purchase Requisition). My client has a requirement to change the document type of the PR (BSART) based on the order type of the WO. I have searched through some exits haven'

  • Db link creation in same db.

    I am trying to create dblink in the same db between schemas . One schema name is clidev2 and other is dbmig. But when i am creating getting below error. Please some one tell me that how can i create db links between the scheams .I have to create dbli

  • Errors in recovery when I switch on laptop

    sir plz help me. there is a problem In my lap hp pavilion g6 2103 tu. recovery errors major problem. what we 'll do???? This question was solved. View Solution.