DataType conflict in the R/3 when joining two tables

Hi Experts,
I have created a view with two table in the R/3 side by joining two common fields,but one of the field is getting error with different data type, so could any one suggest me how to resolve this issue without changing type.
Thanks,
Venugopal

Hi
Actually I have to pull one of the  field from one table and place in other table and create a generic data source on it,Can any one suggest me with any solution or exists to solve this issue.
Thanks,
Venugopal

Similar Messages

  • 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/

  • Problem when joining two tables

    hi,
    in one table i have
    matno mattype
    00001    a
    00002    b
    00003    c
    00004    d
    in table two i have
    vno   matno 
    v001     1
    v002     2
    v003     3
    v004     4
    when i am trying to link these two tables with matno it is not happening
    is it because it is showing '00001' in one table and '1' in other table
    how to fix this
    note:same material info object is their in both the tables

    Hi,
    are your two tables attribute master data tables? Can you paste the names here?
    If as you mention you ae using the same IObj 0MATERIAL, the data in should be the same, unless you didn't turn the conversion routine in the TRules of your second IObj (table vno/matno)
    Please describe with more detail the infoObjects related to your two tables and the TRules associated.
    As a very first check, verify if your material has MATN1 conversion routine and if you have activated it in both TRules; if not, do that, reload your master data, activate it and check it again.
    hope this helps...
    Olivier.

  • Strange problem when joining two tables

    Hi,
    I have recently encountered a strange problem on an Oracle 11gR2 database which is optimized for Datawarehouse usage.
    I am using two tables that have a relationship enforced by two fields of type NUMBER(10).
    The problem is that when I am joining these two tables very often I get strange results and when I re-execute the query I get a different result. I saw in the explain plan that the Hash Join is used for joining these two tables.
    select count(*)
    from recharge_history rh, recharge_history_balance rhb
    where rh.recharge_id = rhb.recharge_id
    and rh.recharge_id2 = rhb.recharge_id2
    and trunc(rh.recharge_date_time) between '30-Dec-2012' and '31-Dec-2012'
    If I explicitly set the Join method to some other type through SQL Hints, or if I use to_number function when joining (even though the two fields used for join in both tables are of NUMBER(10) type), I get the correct result, like for example below:
    select /*+ USE_MERGE (rh rhb) */
    count(*)
    from recharge_history rh, recharge_history_balance rhb
    where rh.recharge_id = rhb.recharge_id
    and rh.recharge_id2 = rhb.recharge_id2
    and trunc(rh.recharge_date_time) between '30-Dec-2012' and '31-Dec-2012'
    select
    count(*)
    from recharge_history rh, recharge_history_balance rhb
    where to_number(rh.recharge_id) = t_number(rhb.recharge_id)
    and to_number(rh.recharge_id2) = (to_number)rhb.recharge_id2)
    and trunc(rh.recharge_date_time) between '30-Dec-2012' and '31-Dec-2012'
    Thank you for your time.
    Edrin

    Hi, Edrin,
    961841 wrote:
    Hi,
    I have recently encountered a strange problem on an Oracle 11gR2 database which is optimized for Datawarehouse usage.
    I am using two tables that have a relationship enforced by two fields of type NUMBER(10).
    The problem is that when I am joining these two tables very often I get strange results and when I re-execute the query I get a different result. I saw in the explain plan that the Hash Join is used for joining these two tables.
    select count(*)
    from recharge_history rh, recharge_history_balance rhb
    where rh.recharge_id = rhb.recharge_id
    and rh.recharge_id2 = rhb.recharge_id2
    and trunc(rh.recharge_date_time) between '30-Dec-2012' and '31-Dec-2012'
    Don't try to compare DATEs with VARCHAR2s, such as '30-Dec-2012'. The VARCHAR2 '31-Aug-2012' is between '30-Dec-2012' and '31-Dec-2012'; so are '31-Aug-2013' and '30-Mar-1999'.
    That may not be your only problem, but it's still a problem.
    If you're getting incosistent results, then it sounds like a bug. Start a service request with Oracle support.

  • How to do proper group by when joining two tables ?

    Hi all,
    Using the below join query, I would like to get output based on number of "Classes" ( For eg: If I want result for 15 classes then , it should return 16 rows from 0 to 16).
    I n below query , I use group by as
    "GROUP BY report_parameters.report_parameter_value  ".
    Error says "its not group by expression".
    If I commented out group by , then it reurns 320 rows instead of 16 rows.
    Could anyone help me?
    SELECT 'SUM('
        || 'CASE '
        || 'WHEN edr_class_by_gvw_report_data.bin_id >= ' || report_range_parameters.report_parameter_min_value || '
             AND edr_class_by_gvw_report_data.bin_id  < ' || report_range_parameters.report_parameter_max_value || '
            THEN edr_class_by_gvw_report_data.bin_value '   
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || report_parameters.report_parameter_value || '" '   
          FROM report_parameters
          JOIN report_range_parameters
            ON report_parameters.report_parameter_id = report_range_parameters.report_parameter_id
         WHERE report_range_parameters.report_parameter_id    = 2316   
           AND report_range_parameters.report_parameter_group = 'GVW_GROUP'
           AND report_range_parameters.report_parameter_name  = 'GVW_NAME'
           AND report_parameters.report_parameter_group = 'CLASS'
           AND report_parameters.report_parameter_name  = 'CLASS'
         GROUP BY
          report_parameters.report_parameter_value 
         ORDER BY  report_range_parameters.report_parameter_min_value ASC;Thanks .
    Edited by: user10641405 on Jun 11, 2009 12:23 PM
    Edited by: user10641405 on Jun 11, 2009 12:30 PM

    Hi Frank,
    Thank you so much for your reply.
    Yes it is the same query.
    Okay, here I will explain what i actually want.
    Below is my final output(No doubt)
    veh weight    class 0    class 1   class 2
    0->5               0          5        10
    5-> 10             0          22       32
    10->15             0          12       67
    In final dynamic sql(which have to generate the above final output), we use 2 functions(called my_class_select_text and my_class_sum_text) to genearte two types of sql strings as below:so the output that I asked is regards this functions' output not the final output.
    "The below  output( is the one I asked previously) is from the my_class_select_text function"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 0 AND edr_class_by_gvw_report_data.gvw  < 5 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 0"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 5 AND edr_class_by_gvw_report_data.gvw  < 10 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 1"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 10 AND edr_class_by_gvw_report_data.gvw  < 15 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 2"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 15 AND edr_class_by_gvw_report_data.gvw  < 20 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 3"
    SUM(CASE WHEN edr_class_by_gvw_report_data.gvw >= 20 AND edr_class_by_gvw_report_data.gvw  < 25 THEN edr_class_by_gvw_report_data.gvw_count ELSE 0 END ) "Class 4"
    "The below output is from the function my_class_sum_text"
    SUM("0->5") "0->5" 
    SUM("5->10") "5->10"
    SUM("10->15") "10->15"
    SUM("15->20") "15->20"
    "here i have pasted those functions.so you could have some better idea"
    FUNCTION edr_rpt_get_class_select_text
         in_report_parameter_id   IN      NUMBER
    RETURN VARCHAR2
    IS
       my_class_select_text  VARCHAR2(32676);
       my_class_select_value VARCHAR2(32676);
       CURSOR class_select_text IS      
          SELECT 'SUM('
        || 'CASE '
        || 'WHEN edr_class_by_gvw_report_data.gvw >='|| report_range_parameters.report_parameter_min_value ||'
             AND edr_class_by_gvw_report_data.gvw  <'|| report_range_parameters.report_parameter_max_value ||'
            THEN edr_class_by_gvw_report_data.gvw_count '   
        || 'ELSE 0 '
        || 'END '
        || ') "Class ' || report_parameters.report_parameter_value || '" '   
          FROM report_parameters
          JOIN report_range_parameters
            ON report_parameters.report_parameter_id = report_range_parameters.report_parameter_id
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'CLASS'
           AND report_parameters.report_parameter_name  = 'CLASS'
           AND report_range_parameters.report_parameter_group = 'GVW_GROUP'
           AND report_range_parameters.report_parameter_name  = 'GVW_NAME'
         ORDER BY CAST(report_parameters.report_parameter_value AS NUMBER) ASC;
    BEGIN
      my_class_select_text := '';
      OPEN class_select_text;
      LOOP
        FETCH class_select_text INTO my_class_select_value;
        EXIT WHEN class_select_text%NOTFOUND;
        my_class_select_text := my_class_select_text || ', ' || my_class_select_value;
      END LOOP;
      CLOSE class_select_text;
      RETURN my_class_select_text;
    END edr_rpt_get_class_select_text;
    FUNCTION edr_rpt_get_class_sum_text
         in_report_parameter_id   IN   NUMBER
    RETURN VARCHAR2
    IS
      my_class_sum_text     VARCHAR2(32676);
      my_class_sum_value    VARCHAR2(32676);
    CURSOR class_sum_text IS
          SELECT  'SUM("' || report_range_parameters.report_parameter_min_value || '->' || report_range_parameters.report_parameter_max_value || '")
              "Class ' || report_parameters.report_parameter_value || '"  '        
           FROM report_range_parameters
          JOIN report_parameters
            ON report_range_parameters.report_parameter_id = report_parameters.report_parameter_id
         WHERE report_range_parameters.report_parameter_id    = in_report_parameter_id   
           AND report_range_parameters.report_parameter_group = 'GVW_GROUP'
           AND report_range_parameters.report_parameter_name  = 'GVW_NAME'
           AND report_parameters.report_parameter_group = 'CLASS'
           AND report_parameters.report_parameter_name  = 'CLASS'
         ORDER BY report_range_parameters.report_parameter_min_value ASC;
    BEGIN
      my_class_sum_text := '';
      OPEN class_sum_text;
      LOOP
        FETCH class_sum_text INTO my_class_sum_value;
        EXIT WHEN class_sum_text%NOTFOUND;
        my_class_sum_text := my_class_sum_text || ', ' || my_class_sum_value;
      END LOOP;
      CLOSE class_sum_text;
      RETURN my_class_sum_text;
    END edr_rpt_get_class_sum_text;Here I'm using one more table called edr_class_by_gvw_report_data.
    gvw                         |  gvw_count
    (veh weight in kips)     (count of veh )
    5                                       3
    12                                    10
    13                                    5
    sample insert statement
    INSERT INTO EDR_CLASS_BY_REPORT_DATA(GVE,GVW_COUNT) VALUES(5,3)
    INSERT INTO EDR_CLASS_BY_REPORT_DATA(GVE,GVW_COUNT) VALUES(12,10)
    INSERT INTO EDR_CLASS_BY_REPORT_DATA(GVE,GVW_COUNT) VALUES(13,5)Below i have pasted portion of my dynamic sql (this is sample from "class by hour report" . It includes "Hour"(That I highlighted in red.It will generate output as
    0-1
    1-2
    2-3
    etc )
    In this place, I need to replace by weight ranges as "Kips" because now the report that I'm working is called "class by gross veh weight".
        || '         SELECT 1 "Rank", '
        || '                ''Data Row'' "Row Type", '
        || '                TRUNC(edr_rpt_tmp_bin_periods.bin_start_date_time ) "Date", '
        || '                edr_rpt_tmp_bin_periods.bin_start_date_time "Date/Time", '
        || '                '''' "Lane", '
      "  || '                TO_CHAR(edr_rpt_tmp_bin_periods.bin_start_date_time, ''hh24'') '"
      "  || '                || '' - '' || ' "
      "  || '                DECODE(TO_CHAR(edr_rpt_tmp_bin_periods.bin_end_date_time, ''hh24''), ''00'', ''24'', TO_CHAR(edr_rpt_tmp_bin_periods.bin_end_date_time, ''hh24'')) "Hour" ' "
        ||                  my_class_sum_text || ', '  "<------------- function generates sql string"
        || '                SUM(NVL(" ", 0)) "Total" '
        || '           FROM ( '
        || '                  SELECT edr_class_by_gvw_report_data.bin_start_date_time start_date_time '
        ||                           my_class_select_text || ', ' "<------------------function generates sql string"
        || '                         SUM(NVL(edr_class_by_gvw_report_data.gvw_count, 0)) " " '
        || '                    FROM edr_class_by_gvw_report_data '
        || '                   GROUP BY edr_class_by_gvw_report_data.bin_start_date_time '
        || '                ) results '
        || '          RIGHT OUTER JOIN edr_rpt_tmp_bin_periods '
        || '             ON results.start_date_time >= edr_rpt_tmp_bin_periods.bin_start_date_time '
        || '            AND results.start_date_time <  edr_rpt_tmp_bin_periods.bin_end_date_time '
        || '          GROUP BY edr_rpt_tmp_bin_periods.bin_start_date_time, '
        || '                edr_rpt_tmp_bin_periods.bin_end_date_time '
        || '          ORDER BY "Date/Time" ASC, '
        || '                "Rank" ASC 'I'm really thankful for your kindness and pain of reading all my blablablaaasss.
    Hope you could have some better understnading by this reply.
    I'm willing to answer all your questions.
    Regards,
    Indhu.
    Edited by: user10641405 on Jun 15, 2009 4:55 PM
    Edited by: user10641405 on Jun 15, 2009 4:59 PM
    Edited by: user10641405 on Jun 15, 2009 5:01 PM
    Edited by: user10641405 on Jun 15, 2009 5:02 PM
    Edited by: user10641405 on Jun 16, 2009 8:29 AM
    Edited by: user10641405 on Jun 16, 2009 8:50 AM
    Edited by: user10641405 on Jun 16, 2009 11:55 AM

  • Join two tables with no matching records

    Hi All,
    I have two tables which have got data as below. Now I need to join those two tables but there are no matching rows or columns in those tables. I have used OUTER JOIN but query was taking more than 5 mnts to run. Whats the best way to join two tables where
    there are no matching records.
    Table : Sections &Table : orders 
    I am expecting the final output like I have mentioned below.
    How can i write a JOIN. Note there are no matching records from both the tables.
    Pls.This is a very urgent requirement.Regards
    -pep

    Thanks Elrand. I have one question. What if I want to add 10 more parameters in @Section table then
    the logic I have written below will not work. I will have to make it dynamic. Any suggestions.?
    declare @test table (RowNo INT,CokeType NVARCHAR(MAX),BeginUsage dateTIME)
    declare @Section table (SectionName NVARCHAR(100))
    insert into @Section values ('CokeType')
    insert into @Section values ('BeginUsage')
    insert into @test values (1,'OMV - 02E (04/2012)','01-02-2014')
    insert into @test values (2,'OMV - 02E (04/2012)','01-03-2014')
    insert into @test values (3,'PCIC - 01 (01E/2013)','01-04-2014')
    insert into @test values (4,'PCIC - 01 (01E/2013)','01-05-2014')
    insert into @test values (5,'PCIC - 01 (E) - 07/2011 & Alba /2010 (C/F) 05/2011','01-06-2014')
    select * from @Section
    select * from @test
    SELECT
    RowNo,SectionName,
    CASE
    WHEN(SectionName = 'CokeType') THEN CokeType
    ELSE
    CAST (BeginUsage AS VARCHAR(MAX))
    END
    AS DATA
    FROM @Section AS S
    CROSS APPLY
    (SELECT T.RowNo,T.CokeType,T.BeginUsage FROM @test T) P
    ORDER BY SectionName DESC

  • Problem encountered when join two remote tables in a materialized view

    I'm using oracle 9.2.0.6
    1> I have two tables:
    CREATE TABLE TEST
    A VARCHAR2(100 BYTE),
    C DATE
    CREATE TABLE TEST1
    A VARCHAR2(100 BYTE),
    B TIMESTAMP
    2>. I defined a prebuild table:
    CREATE TABLE MV_TEST1
    ID1 ROWID,
    A VARCHAR2(100 BYTE),
    ID2 ROWID,
    B TIMESTAMP(6),
    C DATE
    3> I created mview logs:
    CREATE MATERIALIZED VIEW LOG ON PSI_TEST.TEST
    WITH ROWID
    INCLUDING NEW VALUES;
    CREATE MATERIALIZED VIEW LOG ON PSI_TEST.TEST1
    WITH ROWID
    INCLUDING NEW VALUES;
    4> when I create mview:
    CREATE MATERIALIZED VIEW PSI_TEST.MV_TEST1
    ON PREBUILT TABLE WITH REDUCED PRECISION
    REFRESH FAST ON DEMAND
    WITH PRIMARY KEY
    AS
    select
    test.rowid id1,
    test.a,
    test1.rowid id2,
    test1.b,
    cast(null as date) c
    from test , test1
    where test.a = test1.a(+);
    It is created successfully.
    5> problem:
    when I use remote tables to do the same thing, say test and test1 are in another instance and are connected by a dbLink, I couldn't create the mview successfully:
    CREATE MATERIALIZED VIEW PSI_TEST.MV_TEST1
    ON PREBUILT TABLE WITH REDUCED PRECISION
    REFRESH FAST ON DEMAND
    WITH PRIMARY KEY
    AS
    select
    a.rowid id1,
    a.a,
    b.rowid id2,
    b.b,
    cast(null as date) c
    from test@dbl a, test1@dbl b
    where a.a = b.a(+);
    when run above statement, I got:
    ORA-12015: cannot create a fast refresh materialized view from a complex query
    Any ideas? Or joining two table through a dblink for a mview is not allowed at all?
    Thanks in advance.

    No one has a clue?
    Message was edited by:
    lzhwxy

  • 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

  • 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 do you join two tables from different Oracle schemas using a subquery

    I am trying to join two tables from different Oracle schemas using a subquery. I can extract data from each of the tables without a problem. However, when I combine the select statements using a subquery I get the Oracle error *'ORA-00936: missing expression'*. Since each SELECT statement executes on its own without error I don't understand what is missing. The result set I am trying to get is to match up the LINE_ID from PDTABLE_12_1 in schema DD_12809 with the MAT_DESCRIPTION from table PDTABLE_201 in schema RA_12809.
    The query is as follows:
    sql = "SELECT [DD_12809].[PDTABLE_12_1].LINE_ID FROM [DD_12809].[PDTABLE_12_1] JOIN " _
    + "(SELECT [RA_12809].[PDTABLE_201].MAT_DESCRIPTION " _
    + "FROM [RA_12809].[PDTABLE_201]) AS FAB " _
    + "ON [DD_12809].[PDTABLE_12_1].PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS"
    The format of the query is copied from a SQL programming manual.
    I also tried executing the query using a straight JOIN on the two tables but got the same results. Any insight would be helpful. Thanks!
    Edited by: user11338343 on Oct 19, 2009 6:55 AM

    I believe you are receiving the error because you are trying to JOIN on a column that doesn't exist. For example you are trying to join on FAB.PIPING_MATER_CLASS but that column does not exist in the subquery.
    If you want to do a straight join without a subquery you could do the following
    SELECT  DD_12809.PDTABLE_12_1.LINE_ID
    ,       FAB.MAT_DESCRIPTION
    FROM    DD_12809.PDTABLE_12_1
    JOIN    RA_12809.PDTABLE_201    AS FAB ON DD_12809.PDTABLE_12_1.PIPING_MATER_CLASS = FAB.PIPING_MATER_CLASS  HTH!

  • Joining two tables, sql query

    This is a newbie question! I would like to join two tables. Table_1 contains xml stylesheets:
    id stylesheet doc
    1 <xml stylesheet doc A>
    2 <xml stylesheet doc B>
    And Table_2 contains the XML documents that the stylesheets will transform:
    id XML doc
    1 <XML document 1>
    1 <XML document 2>
    1 <XML document 3>
    2 <XML document 4>
    2 <XML document 5>
    I would like <xml stylesheet doc A> to transform only XML doc that have an id of 1, so I tried this sql statement:
    select a.stylesheet_doc ,b.xml_doc from Table_1 a, Table_2 b where a.id=b.id and a.id=1;
    This statement returns the rows I want (stylesheet doc with id equals 1, and xml_doc with id equals 1), but it pairs each xml document with a style sheet.
    stylesheet doc A <XML document 1>
    stylesheet doc A <XML document 2>
    stylesheet doc A <XML document 3>
    My question is, is there a way to have a result that looks like this?
    stylesheet doc A
    <XML document 1>
    <XML document 2>
    <XML document 3>
    That is, is there a way in sql to get rid of duplicate stylesheet doc A?
    I have tried group by and rollup and xmlagg.
    Thank you very, very much for your help.
    Jim

    Hi, Jim,
    Welcome to the forum!
    You just want to display the XML, not actually transform it, right?
    GROUP BY ROLLUP should work, but I find it easier with GROUP BY GROUPING SETS. Here's an example from tables in the scott schema:
    SELECT       CASE
              WHEN  GROUPING (ename) = 1
              THEN  d.dname
           END          AS dname
    ,       e.ename
    FROM       scott.dept     d
    JOIN       scott.emp     e  ON     d.deptno     = e.deptno
    GROUP BY  GROUPING SETS ( (d.dname, e.ename)
                   , (d.dname)
    ORDER BY  d.dname
    ,       ename          NULLS FIRST
    ;Output:
    DNAME          ENAME
    ACCOUNTING
                   CLARK
                   KING
                   MILLER
    RESEARCH
                   ADAMS
                   FORD
                   JONES
                   SCOTT
                   SMITH
    SALES
                   ALLEN
                   BLAKE
                   JAMES
                   MARTIN
                   TURNER
                   WARDYou may have noticed that this site noramlly compresses whitespace.
    Whenever you post formatted text (such as query results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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

  • Joining two tables using PL/SQL

    here i am trying to join two tables can any one tell me what is wrong with this syntex
    CREATE OR REPLACE PROCEDURE test IS
    CURSOR c1 IS SELECT seq,fname,lname from t1;
    CURSOR c2 IS SELECT seq1,q,a from t2;
    userjob number;
    BEGIN
         OPEN c1;
    insert into t3 values(c1.seq,c1.fname,c1.lname);
         FETCH c1.seq INTO userjob;
    FOR c1rec IN c2 LOOP
    IF (c1rec.seq=c1.seq and c1rec.q1='why') THEN
    insert into t3 values(c1rec.q1,c1rec.a1);
    elsif (c1rec.seq=c1.seq and c1rec.q1='what') then
    insert into t3 values(c1rec.q2,c1rec.a2);
    elsif (c1rec.seq=c1.seq and c1rec.q1='when') then
    insert into t3 values(c1rec.q3,c1rec.a3);
    elsif (c1rec.seq=c1.seq and c1rec.q1='where') then
    insert into t3 values(c1rec.q4,c1rec.a4);
         END IF;
         END LOOP;
         END;
    /

    You should always fetch a cursor before using it's values. All columns in the select should be fetched into variables or a record-variable. You can't refer to the cursor-columns values with c1.seq etc.
    r1 c1%rowtype;
    l_found boolean;
    BEGIN
    OPEN c1;
    FETCH c1 INTO r1;
    insert into t3 values(r1.seq,r1.fname,r1.lname);
    l_found := c1%found;
    close c1;
    if l_found
    then
    It is also better to close the cursor and check if the select resulted in a row. With this code you will only retrieve one row even if the select will result in multiple rows.
    But I agree with all the others that this can probably be done more efficiently with one SQL statement.

  • Help in joining two tables

    Hi ,
    I need your help in the below scenario:
    I have two tables.
    One of my table 'table1' contains the below data:
    Code:
    Name,Value
    12A,1
    12B,1
    12C,1
    Table2 contains the below data:
    Code:
    value,result
    1,12
    1,24
    1,56
    1,423
    1,32
    1,3
    I need to join based on value field.
    My expected result is:
    Code:
    NAME,VALUE,RESULT
    12A,1,12
    12B,1,24
    12C,1,56
    12D,1,423
    12E,1,32
    12F,1,3
    Depends on the number of records in the second table,we need to append A to Z at the end of the name field. The number of records will not exceed more than 26. How we can achieve this?
    Thanks
    Pandeeswaran

    OK, now you give another useful information - that there always will be combinations of sums in table2 to match the values in table1. (It is difficult to help when you tell the specs one at a time :-) )
    But it is not easy, because the code really will have to try and consider all possible combinations and then "choosing the right one" - this is easy for us humans, but not easy to encode in programming logic.
    I have made an attempt:
    SQL> set linesize 120
    SQL> with table1 as (
      2     select 'A1' name, 123 id, 150 value from dual union all
      3     select 'A2' name, 123 id, 200 value from dual union all
      4     select 'A3' name, 123 id, 300 value from dual
      5  ), table2 as (
      6     select 123 id, 100 value from dual union all
      7     select 123 id, 100 value from dual union all
      8     select 123 id, 50  value from dual union all
      9     select 123 id, 100 value from dual union all
    10     select 123 id, 100 value from dual union all
    11     select 123 id, 100 value from dual union all
    12     select 123 id, 100 value from dual
    13  )
    14  --
    15  -- End of test data
    16  --
    17  select
    18  t1.id, t1.name, t1.value, t2.value,
    19  t1.rn, t1.minval, t1.maxval,
    20  t2.rn, t2.sumval
    21  from (
    22     select
    23     tab1.*,
    24     nvl(sum(tab1.value) over (
    25        partition by tab1.id
    26        order by tab1.rn
    27        rows between unbounded preceding and 1 preceding
    28     ),0) minval,
    29     sum(tab1.value) over (
    30        partition by tab1.id
    31        order by tab1.rn
    32        rows between unbounded preceding and current row
    33     ) maxval
    34     from (
    35        select
    36        table1.*,
    37        row_number() over (
    38           partition by table1.id
    39           order by table1.value desc
    40        ) rn
    41        from table1
    42     ) tab1
    43  ) t1
    44  join (
    45     select
    46     tab2.*,
    47     sum(tab2.value) over (
    48        partition by tab2.id
    49        order by tab2.rn
    50     ) sumval
    51     from (
    52        select
    53        table2.*,
    54        row_number() over (
    55           partition by table2.id
    56           order by table2.value desc
    57        ) rn
    58        from table2
    59     ) tab2
    60  ) t2
    61  on (t2.id = t1.id)
    62  where t2.sumval > t1.minval
    63  and t2.sumval <= t1.maxval
    64  order by
    65  t1.id,
    66  t1.rn,
    67  t2.rn
    68  ;
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
           123 A3        300        100          1          0        300          1        100
           123 A3        300        100          1          0        300          2        200
           123 A3        300        100          1          0        300          3        300
           123 A2        200        100          2        300        500          4        400
           123 A2        200        100          2        300        500          5        500
           123 A1        150        100          3        500        650          6        600
           123 A1        150         50          3        500        650          7        650
    7 rows selected.It does seem to work for your data sample, but it is much too simple a rule to work in general. My "rule" simply is to order the data by value descending and summing up until "enough" values have been added.
    Consider this data sample instead:
    SQL> with table1 as (
      2     select 'A1' name, 1 id, 100 value from dual union all
      3     select 'A2' name, 1 id, 200 value from dual union all
      4     select 'A3' name, 1 id, 300 value from dual union all
      5     select 'B1' name, 2 id, 100 value from dual union all
      6     select 'B2' name, 2 id, 200 value from dual
      7  ), table2 as (
      8     select 1 id, 25  value from dual union all
      9     select 1 id, 75  value from dual union all
    10     select 1 id, 50  value from dual union all
    11     select 1 id, 50  value from dual union all
    12     select 1 id, 175 value from dual union all
    13     select 1 id, 225 value from dual union all
    14     select 2 id, 25  value from dual union all
    15     select 2 id, 50  value from dual union all
    16     select 2 id, 75  value from dual union all
    17     select 2 id, 100 value from dual union all
    18     select 2 id, 50  value from dual
    19  )
    20  --
    21  -- End of test data
    22  --
    23  select
    24  t1.id, t1.name, t1.value, t2.value,
    25  t1.rn, t1.minval, t1.maxval,
    26  t2.rn, t2.sumval
    27  from (
    28     select
    29     tab1.*,
    30     nvl(sum(tab1.value) over (
    31        partition by tab1.id
    32        order by tab1.rn
    33        rows between unbounded preceding and 1 preceding
    34     ),0) minval,
    35     sum(tab1.value) over (
    36        partition by tab1.id
    37        order by tab1.rn
    38        rows between unbounded preceding and current row
    39     ) maxval
    40     from (
    41        select
    42        table1.*,
    43        row_number() over (
    44           partition by table1.id
    45           order by table1.value desc
    46        ) rn
    47        from table1
    48     ) tab1
    49  ) t1
    50  join (
    51     select
    52     tab2.*,
    53     sum(tab2.value) over (
    54        partition by tab2.id
    55        order by tab2.rn
    56     ) sumval
    57     from (
    58        select
    59        table2.*,
    60        row_number() over (
    61           partition by table2.id
    62           order by table2.value desc
    63        ) rn
    64        from table2
    65     ) tab2
    66  ) t2
    67  on (t2.id = t1.id)
    68  where t2.sumval > t1.minval
    69  and t2.sumval <= t1.maxval
    70  order by
    71  t1.id,
    72  t1.rn,
    73  t2.rn
    74  ;
            ID NA      VALUE      VALUE         RN     MINVAL     MAXVAL         RN     SUMVAL
             1 A3        300        225          1          0        300          1        225
             1 A2        200        175          2        300        500          2        400
             1 A2        200         75          2        300        500          3        475
             1 A1        100         50          3        500        600          4        525
             1 A1        100         50          3        500        600          5        575
             1 A1        100         25          3        500        600          6        600
             2 B2        200        100          1          0        200          1        100
             2 B2        200         75          1          0        200          2        175
             2 B1        100         50          2        200        300          3        225
             2 B1        100         50          2        200        300          4        275
             2 B1        100         25          2        200        300          5        300
    11 rows selected.In this dataset the simple ordering by value will not work - It should have been A3: (225,75), A2: (175,25) and A1: (50,50).
    I cannot really think of a reasonably simple way to do it in SQL alone. Maybe using the MODEL clause would be possible, but not trivial. It is possible it would be easier to solve this in PL/SQL by iterating through a couple of arrays and intelligently trying the different combinations, rather than brute-force creating all combinations in a huge piece of SQL.
    I am sorry, Pandeesh, but I can not think of a solution easily.
    I might be able to do something if I fiddled with the problem for a couple of days, but that would be beyond the scope of this forum. That would be a consulting job rather than a bit of forum help :-)

  • How to join two tables

    hi
    how to join two tables using inner join  if the first table has two primary keys and second table has 3 primary keys

    Would describe type of joins in ABAP, which might differ with other joins.
    The join syntax represents a recursively nestable join expression. A join expression consists of a left-hand and a right- hand side, which are joined either by means of INNER JOIN or LEFT OUTER JOIN. Depending on the type of join, a join expression can be either an inner (INNER) or an outer (LEFT OUTER) join. Every join expression can be enclosed in round brackets. If a join expression is used, the SELECT command circumvents SAP buffering.
    On the left-hand side, either a single database table, a view dbtab_left, or a join expression join can be specified. On the right-hand side, a single database table or a view dbtab_right as well as join conditions join_cond can be specified after ON. In this way, a maximum of 24 join expressions that join 25 database tables or views with each other can be specified after FROM.
    AS can be used to specify an alternative table name tabalias for each of the specified database table names or for every view. A database table or a view can occur multiple times within a join expression and, in this case, have various alternative names.
    The syntax of the join conditions join_cond is the same as that of the sql_cond conditions after the addition WHERE, with the following differences:
    At least one comparison must be specified after ON.
    Individual comparisons may be joined using AND only.
    All comparisons must contain a column in the database table or the view dbtab_right on the right-hand side as an operand.
    The following additions not be used: NOT, LIKE, IN.
    No sub-queries may be used.
    For outer joins, only equality comparisons (=, EQ) are possible.
    If an outer join occurs after FROM, the join condition of every join expression must contain at least one comparison between columns on the left-hand and the right-hand side.
    In outer joins, all comparisons that contain columns as operands in the database table or the view dbtab_right on the right-hand side must be specified in the corresponding join condition. In the WHERE condition of the same SELECT command, these columns are not allowed as operands.
    Resulting set for inner join
    The inner join joins the columns of every selected line on the left- hand side with the columns of all lines on the right-hand side that jointly fulfil the join_cond condition. A line in the resulting set is created for every such line on the right-hand side. The content of the column on the left-hand side may be duplicated in this case. If none of the lines on the right-hand side fulfils the join_cond condition, no line is created in the resulting set.
    Resulting set for outer join
    The outer join basically creates the same resulting set as the inner join, with the difference that at least one line is created in the resulting set for every selected line on the left-hand side, even if no line on the right-hand side fulfils the join_cond condition. The columns on the right-hand side that do not fulfil the join_cond condition are filled with null values.
    Note
    If the same column name occurs in several database tables in a join expression, they have to be identified in all remaining additions of the SELECT statement by using the column selector ~.
    Example
    Join the columns carrname, connid, fldate of the database tables scarr, spfli and sflight by means of two inner joins. A list is created of the flights from p_cityfr to p_cityto. Alternative names are used for every table.
    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.
    SELECT ccarrname pconnid f~fldate
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM ( ( scarr AS c
    INNER JOIN spfli AS p ON pcarrid = ccarrid
    AND p~cityfrom = p_cityfr
    AND p~cityto = p_cityto )
    INNER JOIN sflight AS f ON fcarrid = pcarrid
    AND fconnid = pconnid ).
    LOOP AT itab INTO wa.
    WRITE: / wa-fldate, wa-carrname, wa-connid.
    ENDLOOP.
    Example
    Join the columns carrid, carrname and connid of the database tables scarr and spfli using an outer join. The column connid is set to the null value for all flights that do not fly from p_cityfr. This null value is then converted to the appropriate initial value when it is transferred to the assigned data object. The LOOP returns all airlines that do not fly from p_cityfr.
    PARAMETERS p_cityfr TYPE spfli-cityfrom.
    DATA: BEGIN OF wa,
    carrid TYPE scarr-carrid,
    carrname TYPE scarr-carrname,
    connid TYPE spfli-connid,
    END OF wa,
    itab LIKE SORTED TABLE OF wa
    WITH NON-UNIQUE KEY carrid.
    SELECT scarrid scarrname p~connid
    INTO CORRESPONDING FIELDS OF TABLE itab
    FROM scarr AS s
    LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid
    AND p~cityfrom = p_cityfr.
    LOOP AT itab INTO wa.
    IF wa-connid = '0000'.
    WRITE: / wa-carrid, wa-carrname.
    ENDIF.
    ENDLOOP.

Maybe you are looking for

  • Error on Parked Logical Invoices

    Hello everyone, I have a problem with posting logical invoices in a new fiscal year. Parked logical invoices are getting a hard error when users attempt to process the invoice in the new fiscal year. Do you have any idea how to make it work? The last

  • RDP to hyper-v host sever core

    Hi, Is there a way to RDP to a hyper-V host server from any windows OS ? Thanks

  • Sdi1.setDisclosed(true) not working correctly

    Hi all, I use Jdev 11g. I created a page with a table and two tabs. When a new row is selected in the table then tab1 should be shown if tab2 was selected.. I use this code:     public void rowSelected(SelectionEvent selectionEvent) {         reslove

  • Can't record video's in iOS7 on iPAD 3th generation

    I just upgraded my iPAD 3th generation to iOS7 ( it seems to be very slow ) and now I can't record any video's anymore in camera. I can't seem to select video or square format, so i'm stuck with only taking pictures? Please help.

  • T400 Not shutting down due to driver error.

    Hello! I have recently purchased a refurbished IBM ThinkPad T400 (TYPE: 2767 DM9). The laptop came shipped with Windows XP SP2 Professional 32 Bit; originally in great working condition. However, I had it upgraded to Windows 7 SP1 32Bit Professional