Select and calculate average on joining two tables - normal and archive.

Hello,
I am in process of writing a query to calculate (daily/or weekly/or monthly)average time taken by orders raised from different system. Order creation date is in one table, and order finalization date is in another table.
Now both these tables are getting archived every three months, so in order to get the average for orders before these three months, i am forced to make an union of two archive tables for entry date, and two archives table for the end date. And this query is taking a lot of time to be executed. I am not a DB guy and have less idea of running the execution plan. Any help on this will be a great help for me.
My current query is as below:
SELECT DOP.SYSTEMID,AVG( H1.ENTRYDATE - DOP.ENTRYDATE) AS AVERAGETIME,
            TO_CHAR(DOP.ENTRYDATE ,'DD/MM/YY')  AS CREATIONDATE
              FROM (
                 SELECT SYSTEMID,ENTRYDATE, INTERNALORDERID FROM ORDERS_TAB WHERE
                    ENTRYDATE
                    BETWEEN TO_DATE('01/10/2008','DD/MM/YY')
                    AND TO_DATE('21/10/2009','DD/MM/YY')
                 UNION  ALL
                 SELECT SYSTEMID,ENTRYDATE, INTERNALORDERID FROM ORDERS_TAB_ARCH
                    WHERE ENTRYDATE
                    BETWEEN TO_DATE('01/10/2008','DD/MM/YY')
                    AND TO_DATE('21/10/2009','DD/MM/YY')
                 )  DOP, 
                 SELECT ENTRYDATE,INTERNALORDERID FROM ORDERS_HEAD_HISTORY
                 WHERE
                    ENTRYDATE >TO_DATE('01/10/2008','DD/MM/YY')  AND STATUSID = 7
                 UNION ALL
                 SELECT ENTRYDATE,INTERNALORDERID FROM ORDERS_HEAD_HIST_ARCH
                    WHERE ENTRYDATE >TO_DATE('01/08/2008','DD/MM/YY')  AND STATUSID = 7 
                 ) H1
                   WHERE DOP.INTERNALORDERID=H1.INTERNALORDERID
                   GROUP BY DOP.MASTERSYSTEMID, TO_CHAR(DOP.ENTRYDATE ,'DD/MM/YY')Regards,
Edited by: A R on Oct 23, 2009 9:37 AM

Thanks etbin. Yes I am joining the archive table only when the date contains that of archive data. I am doing it conditionally via java.
@damorgan.
Version:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production
"CORE     10.2.0.3.0     Production"
TNS for Solaris: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
Query plan
<ExplainPlan>
  <PlanElement object_ID="0" id="0" operation="SELECT STATEMENT" optimizer="ALL_ROWS" cost="276.594" cardinality="12.565" bytes="678.510" cpu_cost="38.788.639.859" io_cost="266.656" time="1.646">
    <PlanElements>
      <PlanElement object_ID="0" id="1" operation="HASH" option="GROUP BY" cost="276.594" cardinality="12.565" bytes="678.510" cpu_cost="38.788.639.859" io_cost="266.656" time="1.646">
        <PlanElements>
          <PlanElement object_ID="0" id="2" operation="NESTED LOOPS" cost="276.591" cardinality="12.565" bytes="678.510" cpu_cost="38.777.027.861" io_cost="266.656" time="1.646">
            <PlanElements>
              <PlanElement object_ID="1" id="3" operation="VIEW" object_owner="HIDE_USER" object_instance="4" cost="276.587" cardinality="2" bytes="48" cpu_cost="38.777.004.963" io_cost="266.652" time="1.646">
                <PlanElements>
                  <PlanElement object_ID="0" id="4" operation="UNION-ALL">
                    <PlanElements>
                      <PlanElement object_ID="0" id="5" operation="PARTITION LIST" option="ALL" cost="55.239" cardinality="1" bytes="17" partition_start="1" partition_stop="12" partition_id="5" cpu_cost="5.061.473.580" io_cost="53.942" time="329">
                        <PlanElements>
                          <PlanElement object_ID="2" id="6" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_HEAD_HISTORY" object_type="TABLE" object_instance="5" cost="55.239" cardinality="1" bytes="17" partition_start="1" partition_stop="12" partition_id="5" cpu_cost="5.061.473.580" io_cost="53.942" filter_predicates="&quot;ENTRYDATE&quot;&gt;TO_DATE('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND &quot;STATUSID&quot;=7" time="329"/>
                        </PlanElements>
                      </PlanElement>
                      <PlanElement object_ID="0" id="7" operation="PARTITION LIST" option="ALL" cost="221.348" cardinality="1" bytes="17" partition_start="1" partition_stop="12" partition_id="7" cpu_cost="33.715.531.383" io_cost="212.710" time="1.318">
                        <PlanElements>
                          <PlanElement object_ID="3" id="8" operation="TABLE ACCESS" option="FULL" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_HEAD_HIST_ARCH" object_type="TABLE" object_instance="6" cost="221.348" cardinality="1" bytes="17" partition_start="1" partition_stop="12" partition_id="7" cpu_cost="33.715.531.383" io_cost="212.710" filter_predicates="&quot;ENTRYDATE&quot;&gt;TO_DATE('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND &quot;STATUSID&quot;=7" time="1.318"/>
                        </PlanElements>
                      </PlanElement>
                    </PlanElements>
                  </PlanElement>
                </PlanElements>
              </PlanElement>
              <PlanElement object_ID="1" id="9" operation="VIEW" object_owner="HIDE_USER" object_instance="1" cost="2" cardinality="1" bytes="30" cpu_cost="11.449" io_cost="2" time="1">
                <PlanElements>
                  <PlanElement object_ID="0" id="10" operation="UNION ALL PUSHED PREDICATE">
                    <PlanElements>
                      <PlanElement object_ID="4" id="11" operation="TABLE ACCESS" option="BY GLOBAL INDEX ROWID" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_TAB" object_type="TABLE" object_instance="2" cost="1" cardinality="1" bytes="23" partition_start="ROW LOCATION" partition_stop="ROW LOCATION" partition_id="11" cpu_cost="5.730" io_cost="1" filter_predicates="&quot;ENTRYDATE&quot;&gt;=TO_DATE('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND &quot;ENTRYDATE&quot;&lt;=TO_DATE('2009-10-21 00:00:00', 'yyyy-mm-dd hh24:mi:ss')" time="1">
                        <PlanElements>
                          <PlanElement object_ID="5" id="12" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_TAB_PK" object_type="INDEX (UNIQUE)" search_columns="1" cost="1" cardinality="1" cpu_cost="3.823" io_cost="1" access_predicates="&quot;INTERNALORDERID&quot;=&quot;H1&quot;.&quot;INTERNALORDERID&quot;" time="1"/>
                        </PlanElements>
                      </PlanElement>
                      <PlanElement object_ID="6" id="13" operation="TABLE ACCESS" option="BY GLOBAL INDEX ROWID" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_TAB_ARCH" object_type="TABLE" object_instance="3" cost="1" cardinality="1" bytes="23" partition_start="ROW LOCATION" partition_stop="ROW LOCATION" partition_id="13" cpu_cost="5.719" io_cost="1" filter_predicates="&quot;ENTRYDATE&quot;&gt;=TO_DATE('2009-06-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss') AND &quot;ENTRYDATE&quot;&lt;=TO_DATE('2009-10-21 00:00:00', 'yyyy-mm-dd hh24:mi:ss')" time="1">
                        <PlanElements>
                          <PlanElement object_ID="7" id="14" operation="INDEX" option="UNIQUE SCAN" optimizer="ANALYZED" object_owner="HIDE_OBJECT_OWNER" object_name="ORDERS_TAB_A_PK" object_type="INDEX (UNIQUE)" search_columns="1" cost="1" cardinality="1" cpu_cost="3.823" io_cost="1" access_predicates="&quot;INTERNALORDERID&quot;=&quot;H1&quot;.&quot;INTERNALORDERID&quot;" time="1"/>
                        </PlanElements>
                      </PlanElement>
                    </PlanElements>
                  </PlanElement>
                </PlanElements>
              </PlanElement>
            </PlanElements>
          </PlanElement>
        </PlanElements>
      </PlanElement>
    </PlanElements>
  </PlanElement>
</ExplainPlan>All the columns involved are index.

Similar Messages

  • Joining two tables LIKP and VBUK

    HI,
    I want to join two tables LIKP and VBUK, can u give some explaination ?
    points will be given for good answers...
    regards
    Vijaya

    Hi,
    see this example of joining two tables zairln & zflight.
    These 2 tables are logically joined by the airln field.
    Select a~airln
           a~lnnam
           b~fligh
           b~cntry
    Into table int_airdet
    From zairln as a inner join zflight as b on aairln = bairln.
    In order to restrict the data as per the selection criteria, a where clause can be added to the above inner join.
    rgds,
    latheesh
    Message was edited by: Latheesh Kaduthara

  • Join two  tables BKPF and VBRK

    I need a report that will join two  tables BKPF and VBRK in QuickViewer. The only field with the right character length is XBLNR but when creating the join no records are dispalyed beacuse the values of this field in both tables are not the same.
    There are also other fields available in BKPF but the char length is not the appropriate.
    Does anyone have any idea how I can link these two tables?
    Thank you

    Neither  of these combinations  is possible with QuickViewer because the fields need to have the same length of characters in order to create the join.
    VBRK - VBLEN char(10) and BKPF - AWKEY char(20)
    VBRK -ZUONR char(18)     BKPF- BELNR char (10)
    Any other idea?
    Thank you, JP

  • Join two tables FBL5N and collection management

    Hi All,
    I want to join two tables i.e T code FBL5N and table UDM_P2P_ATTR. But I am unable to see common fields/tables between the two. Can anyone suggest how can I join this in SE11. Pls suggest the common fiels between two indipendent tables.
    Thanks,
    Vishal Pant
    Edited by: vishal_pant on Jul 19, 2010 12:04 PM

    Neither  of these combinations  is possible with QuickViewer because the fields need to have the same length of characters in order to create the join.
    VBRK - VBLEN char(10) and BKPF - AWKEY char(20)
    VBRK -ZUONR char(18)     BKPF- BELNR char (10)
    Any other idea?
    Thank you, JP

  • How to optimize query that returns data based on one matching and one missing field joining two tables

    Hi all,
    Here is what I am trying to do. I have 2 tables A and B. Both have a fiscal year and a school ID column. I want to return all data from table B where all school IDs match but fiscal year from A is not in B. I wrote 2 queries below but this took
    2 minutes each to process through 30,000 records in table B. Need to optmize this query.
    1) select 1 from table A inner join table B
    on A.SchoolID=B.SchoolID where A.Year not in (select distinct Year from table B)
    2) select distinct Year from Table A where School ID in (select distinct School ID from table B
    and Year not in (select distinct Year from table B)

    Faraz81,
    query execution time will depend not only on your data volume and structure but also on your system resources.
    You should post your execution plans and DDL to generate data structures so we can take a better look, but one think you could try right away is to store the results of the subquery in a table variable and use it instead.
    You'll also benefit from the creation of:
    1. An index for the B.SchoolID column.
    2. Statistics for the Year column in table B.
    You can also try to change the physical algorithm used to join A to B by using query hints (HASH, MERGE, LOOP) and see how they perform. For example:
    select 1 from table A inner HASH join table B
    on A.SchoolID=B.SchoolID where A.Year not in (select distinct Year from table B)
    As the query optimizer generally chooses the best plan, this might not be a good idea though, but then again, without further information its going to be hard to help you.

  • Joining Two Tables based on Conditions.

    Hi All,
    i would like to join two tables emp and dept with conditional join like
    for example: select emp.column1...............
    left outer join DEPT ON if Dept.column1='A" then emp.column1=dept.column1
    else emp.column2=dept.column3
    i know that bu using the UNION we can dothis, but i donot want to USE UNION.
    please let me know if any workaround for this.
    Thanks,
    Kalyan

    SQL> select * from etl
      2  /
         EMPNO ENAME      JOB              MGR        SAL       COMM     DEPTNO AAA                     DEPT_NO
          7566 JONES      MANAGER         7839       2975                    20 2                         20
          7654 MARTIN     SALESMAN        7698       1250       1400         30 3                         10
          7698 BLAKE      MANAGER         7839       2850                    30 3                         10
          7782 CLARK      MANAGER         7839       2450                    10 1                         20
          7788 SCOTT      ANALYST         7566       3000                    20 2                         20
          7839 KING       PRESIDENT                  5000                    10 1                         20
          7844 TURNER     SALESMAN        7698       1500                    30 3                         10
          7876 ADAMS      CLERK           7788       1100                    20 2                         20
          7900 JAMES      CLERK           7698        950                    30 3                         10
          7902 FORD       ANALYST         7566       3000                    20 2                         20
          7934 MILLER5    CLERK           7782       1300                    10 1                         20
          7936 MILLER7    CLERK           7782       1300                    10 1                         20
    12 rows selected.
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> ed
    Wrote file afiedt.buf
      1  select
      2     e.empno,
      3     e.ename,
      4     e.deptno,
      5     aaa,
      6     e.dept_no,
      7     d.deptno,
      8     d.dname
      9  from
    10     etl e ,
    11     dept d
    12  where
    13     (e.aaa =1 and e.deptno = d.deptno) or
    14*    (e.aaa =2 and e.dept_no =d.deptno)
    SQL> /
         EMPNO ENAME          DEPTNO AAA                     DEPT_NO     DEPTNO DNAME
          7566 JONES              20 2                            20         20 RESEARCH
          7788 SCOTT              20 2                            20         20 RESEARCH
          7876 ADAMS              20 2                            20         20 RESEARCH
          7902 FORD               20 2                            20         20 RESEARCH
          7782 CLARK              10 1                            20         10 ACCOUNTING
          7839 KING               10 1                            20         10 ACCOUNTING
          7934 MILLER5            10 1                            20         10 ACCOUNTING
          7936 MILLER7            10 1                            20         10 ACCOUNTING
    8 rows selected.Regards
    Singh

  • Joining Two Tables by Database View

    HI There,
    I'm trying to join two tables BNKA and LFBK to get the Bank details according to the requirement.
    Now, I wanted to go head and create a Generic datasource and bring the fields from these two tables by Vew.
    Can someone please explain me step by step to create the database view?
    One more thing, do we need to have anything in common between two tables BNKA and LFBK ?
    I really appreciate if someone can guide me through step by step method to create Database Table view?
    Thanks
    Madhuri

    Hi Madhuri,
    With out having common fields, we can not create data base view based on two tables.
    1) goto SE11
    2) select data base view and give the name and create.
    3) in left side give the tables names
    4)  In left side define the relation
    check the below article
    http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10a89c00-7dd7-2d10-6f83-cd24ee6d517c?QuickLink=index&overridelayout=true
    Regards,
    Venkatesh

  • Two tables KUWEV and KUAGV joining

    Hi all,
    I have two tables KUWEV and KUAGV
    The following field I have taken  from two tables
    KUWEV u2013VABED
    KUWEV- LLAND
    KUAGV-LAND1
    If  KUWEV u2013VABED =TRLOZ  - VABED
      and KUWEV- LLAND =  TRLOZ  - LLAND
        and KUAGV-LAND1 =  TRLOZ  - LAND1
    then only I have to pickup TRLOZ- ROUTE
    after that i have to  Substitute  the value in VBAP-ROUTE
    can anybody help  to write the code
    I have doubt that how can  data we will pick up 2 fields from one table 1 field from another table and two tables (KUWEV and KUAGV) having common field KUNNR
    Pointes will be rewarded by useful information
    Thanks in advance
    krishna

    Hi KCH,
    either use joins or write separate select statements.
    Hope it helps.
    Aditya

  • Joining two tables having no common fields using one select query

    Hi Experts,
    How to join two tables which are NOT having any field in common using only one select query?
    Your help will be appreciated.
    Thank you.

    Identify a third table (or more tables) with common fields with your two tables, or change your question either removing JOIN or removing NO COMMON FIELDS, else you wont get many responses and will be left alone in outer space, as suggested by Thomas.
    If you acturally require what you written, better execute two select and merge the two internal tables merging every record from first table with every record of second table, til no more memory is available.
    Regards,
    Raymond

  • How do I join two tables in the same database and load the result into a destination table in a SSIS package

    Hi,
    I have a query that joins two tables in the same database, the result needs to be loaded in a destination DB table.  How do I do this in SSIS package?
    thank you !
    Thank You Warmest Fanny Pied

    Please take a look at these links related to your query.
    http://stackoverflow.com/questions/5145637/querying-data-by-joining-two-tables-in-two-database-on-different-servers
    http://stackoverflow.com/questions/7037228/joining-two-tables-together-in-one-database

  • Need help to join two tables using three joins, one of which is a (between) date range.

    I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
    the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
    ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
    [ABCTABLE]
    ABCORDER
    ABCPART
    ABCSERIAL
    ABCDATE
    [ZYXTABLE]
    XYZORDER
    XYZPART
    XYZSERIAL
    XYZDATE1
    XYZDATE2

    Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
    on this computer. There are no "Null" fields in either of the tables. 
    This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
    [MSORDR]
    MSORDER
    MSPART
    MSSERIAL
    MSOPNDATE
    11111111
    4444444
    55555
    2/4/2015
    22222222
    6666666
    11111
    1/6/2015
    33333333
    6666666
    11111
    3/5/2015
    This table has one order for every part number and every serial number.
    [GLORDR]
    GLORDER
    GLPART
    GLSERIAL
    GLSTARTDATE
    GLENDDATE
    ABC11111
    444444
    55555
    1/2/2015
    4/4/2015
    ABC22222
    666666
    11111
    1/5/2015
    4/10/2015
    AAA11111
    555555
    22222
    3/2/2015
    4/10/2015
    Post Query table
    GLORDER
    MSORDER
    GLSTARTDATE
    GLENDDATE
    MSOPNDATE
    ABC11111
    11111111
    1/2/2015
    4/4/2015
    2/4/2015
    ABC22222
    22222222
    1/5/2015
    4/10/2015
    1/6/2015
    ABC22222
    33333333
    1/5/2015
    4/10/2015
    3/5/2015
    This is the SQL minus the between date join.
    SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
    FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART);

  • Using a view to join two tables

    Thank you in advance for any advice you can lend.
    I am using this code in my MySQL db to create a view.
    select
        job.id as job_id,
        umr_cost_calculation.plant_name,
        max(umr_cost_calculation.id) as max_id
    from
        job,
        umr_cost_calculation
    where
        job.id = umr_cost_calculation.job_id
    group by job.id , umr_cost_calculation.plant_name
    I did this so I can join two tables and pull in the most current cost data for a specific plant. The report will, at times, show the wrong (older) data. I can re-run the report, filter to just the one job and see again the wrong data. When I add the max_id to the report, it display the id and updates the report with the correct data. It appears that the view was stale and by adding the ID to the report this fixed the issue.
    1) Is this the best way to make this join? I don't see how Crystal supports a subquery to make a join (this is why I used the view).
    2) If I leave the max_id on the report, will this force the view to always update?

    Try:
    Select
    D1.EmpLoginID,
    Count(D1.ID),
    Count(D1.AlarmCode),
    D1.EmpName,
    D1.EmpAddress,
    D2.Db2Count
    FROM DB1.Data D1
    LEFT JOIN (SELECT
    empLoginID, Count(*) as Db2Count
    FROM DB2.ALL_Database
    WHERE site = 'Atlanta'
    GROUP BY empLoginID
    ) D2
    ON D1.EmpLoginID = D2.EmpLoginID
    GROUP BY D1.empLoginID, D1.EmpName, D2.EmpAddress, D2.Db2Count
    Order BY D1.empLoginID ASC
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • How to prevent Oracle from using an index when joining two tables ...

    How to prevent Oracle from using an index when joining two tables to get an inline view which is used in an update statement?
    O.K. I think I have to explain what I mean:
    When joining two tables which have many entries sometimes it es better not to use an index on the column used as join criteria.
    I have two tables: table A and table B.
    Table A has 4.000.000 entries and table B has 700.000 entries.
    I have a join of both tables with a numeric column as join criteria.
    There is an index on this column in table A.
    So I instead of
      where (A.col = B.col)I want to use
      where (A.col+0 = B.col)in order to prevent Oracle from using the index.
    When I use the join in a select statement it works.
    But when I use the join as inline view in an update statement I get the error ORA-01779.
    When I remove the "+0" the update statement works. (The column col is unique in table B).
    Any ideas why this happens?
    Thank you very much in advance for any help.
    Regards Hartmut

    I think you should post an properly formatted explain plan output using DBMS_XPLAN.DISPLAY including the "Predicate Information" section below the plan to provide more details regarding your query resp. update statement. Please use the \[code\] and \[code\] tags to enhance readability of the output provided:
    In SQL*Plus:
    SET LINESIZE 130
    EXPLAIN PLAN FOR <your statement>;
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);Usually if you're using the CBO (cost based optimizer) and have reasonable statistics gathered on the database objects used the optimizer should be able to determine if it is better to use the existing index or not.
    Things look different if you don't have statistics, you have outdated/wrong statistics or deliberately still use the RBO (rule based optimizer). In this case you would have to use other means to prevent the index usage, the most obvious would be the already mentioned NO_INDEX or FULL hint.
    But I strongly recommend to check in first place why the optimizer apparently seems to choose an inappropriate index access path.
    Regards,
    Randolf
    Oracle related stuff:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle:
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Joining two tables in PL/SQL

    Hi there,
    I have two problems...first being:
    We are trying to run a sub-query within a WHERE/AND clause. I am not sure on the correct syntax on how to run the sub-query as denoted in the code below. Secondly I am trying to join two tables with a common column name (ie: CIPIDI_NR). Considering I cant fix the first problem I cant test out the sub-query. So any help on either would be grateful. Cheers
    Select *
    from TBL_CIPIDI
         WHERE CIPIDI_NR like nvl ('in_case_number%', CIPIDI_NR)
    AND CIPIDI_NAME like nvl ('in_case_name%', CIPIDI_NAME)
    AND COST_CENTRE LIKE NVL ('in_cost_centre%', COST_CENTRE)
    AND CIPIDI_DESCRIPTION like nvl ('in_description%', CIPIDI_DESCRIPTION)
    AND CLAIMANT_NAME LIKE NVL ('in_claimant%', CLAIMANT_NAME)
    AND REQUESTOR LIKE NVL ('in_requestor%', REQUESTOR)
    AND PROJECT_MANAGER LIKE NVL ('in_project_manager%', PROJECT_MANAGER)
    AND TEAM_LEADER LIKE NVL ('in_team_leader%', TEAM_LEADER)
         AND ********RUN THE QUERY BELOW************
    SELECT C1.CIPIDI_NR, C2.CIPIDI_NR
    from TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
         WHERE C1.CIPIDI_NR = C2.CIPIDI_NR
         AND TEAM_MEM_NAME LIKE NVL ('in_team_mem_name%', TEAM_MEM_NAME)
    );

    You really need to start providing create table and insert statements for tables and sample data for testing, the results that you want based on that data in order to clarify the problem, your Oracle version, and a copy and paste of an attempted run of your code, complete with any error messages received. The following is my best guess at what you might be looking for.
    Select *
    from   TBL_TEAM_MEMBERS C1, TBL_CIPIDI C2
    WHERE  C1.CIPIDI_NR = C2.CIPIDI_NR
    AND    c1.CIPIDI_NR          like nvl (in_case_number     || '%', c1.CIPIDI_NR)
    AND    c1.CIPIDI_NAME        like nvl (in_case_name       || '%', c1.CIPIDI_NAME)
    AND    c1.COST_CENTRE        LIKE NVL (in_cost_centre     || '%', c1.COST_CENTRE)
    AND    c1.CIPIDI_DESCRIPTION like nvl (in_description     || '%', c1.CIPIDI_DESCRIPTION)
    AND    c1.CLAIMANT_NAME      LIKE NVL (in_claimant        || '%', c1.CLAIMANT_NAME)
    AND    c1.REQUESTOR          LIKE NVL (in_requestor       || '%', c1.REQUESTOR)
    AND    c1.PROJECT_MANAGER    LIKE NVL (in_project_manager || '%', c1.PROJECT_MANAGER)
    AND    c1.TEAM_LEADER        LIKE NVL (in_team_leader     || '%', c1.TEAM_LEADER)
    AND    TEAM_MEM_NAME         LIKE NVL (in_team_mem_name   || '%', TEAM_MEM_NAME);

  • Joining the Tables VBAK and CDHDR

    Hi All,
    I am a novice to SAP, and probably have the most basic question. I need to join the two tables VBAK and CDHDR and I dont see any common fields between them.
    I would need to do this for as generating a custom report that lists all the valid contracts created or changed within the period of selection. I also need to show the old value and the new value, the user ID of who made the change/creation and the date of the change.
    Anyhelp in this regard is highly appreciated and will be rewarded appropriately.
    Many thanks in anticipation.

    CDHDR is used for each and every table of SAP, so don't look for common key with your table.
    Look for records in CDHDR with OBJECTCLAS = 'VERKBELEG' and OBJECTID = VBAK-VBELN, and then in CDPOS with keys of CDHDR and tabname = 'VBAK'  and tabkey = VBAK-VBELN. (You also get VBAP and other tables under the same Id)
    Take a look at report RVSCD100
    Regards

Maybe you are looking for