Sum of qty of four tables comapring with other table

I had four tables voy,bl,subbl,dcd, i have to find sum of qty form SUBBL and qty from DCD for all subbl group by CCD
TABLE VOY
INTVCN VCN
10 TEST
TABLE BL
VCN BL
10 200
10 201
TABLE SUBBL
subbl     bl     subbl     ccd     qty
100     200     s1     c1     100
101     200     s2     c1     60
102     200     S3     C2     20
103     201     s1     c1     40
104     201     s2     c1     20
TABLE DCD
crg_seq_no     subbl     qty      weight
     1     100     50     
     2     100     25     
     3     101     30     
     4     101     20     
     5     102     20     
     6     103     20     
     7     103     10     
     8     104     20     
Following query was executed but we are getting wrong sum for qty (SUBBL)
Query
select d.ccd,sum(d.qty),sum(f.qty) from
(Select distinct a.ccd,a.subbl,a.qty from subbl A, bl B, voy C
Where a.bl = b.bl and b.vcn = c. intvcn and c. vcn = 'TEST') D,subbl E, dcd F
where d.ccd = e.ccd and d.subbl = e.subbl and d.subbl = f.subbl
group by d.ccd
Result
CCD SUM(D.QTY) SUM(F.QTY)
C1 420 175
C2 20 20
Expected result
CCD SUM(D.QTY) SUM(F.QTY)
C1 220 175
C2 20 20

Hi,
This query is OK with you.
But i don't know why you use distinct in first inline view
select d.ccd,sum(d.qty),sum(f.qty) from
(Select distinct a.ccd,a.subbl,a.qty from subbl A, bl B, voy C
Where a.bl = b.bl and b.vcn = c. intvcn and c. vcn = 'TEST') D,
(select subbl,sum(qty) qty from dcd group by subbl) F
where d.subbl = f.subbl
group by d.ccd
Bye
Chitta

Similar Messages

  • Using Pipeline Table functions with other tables

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables. In my tests, selecting from just the pipelined table perform pretty well (whether it is directly from the pipleined table or the view I created on top of it). Where I start to see some degregation when I try to join the pipelined tabe view to other tables and add where conditions.
    ie:
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'
    I have seen some articles and blogs that mention this as a cardinality issue, and offer some undocumented methods to try and combat.
    Can someone please give me some advice or tips on this. Thanks!
    I have created a simple example using the emp table below to help illustrate what I am doing.
    DROP TYPE EMP_TYPE;
    DROP TYPE EMP_SEQ;
    CREATE OR REPLACE TYPE EMP_SEQ AS OBJECT
           ( EMPNO                                         NUMBER(10),
             ENAME                                         VARCHAR2(100),
             JOB                                           VARCHAR2(100));
    CREATE OR REPLACE TYPE EMP_TYPE AS TABLE OF EMP_SEQ;
    CREATE OR REPLACE FUNCTION get_emp return EMP_TYPE PIPELINED AS
    BEGIN
      FOR cur IN (SELECT
                    empno,
                    ename,
                    job
                  FROM emp
             LOOP
               PIPE ROW(EMP_SEQ(cur.empno,
                                cur.ename,
                                cur.job));
             END LOOP;
             RETURN;
    END get_emp;
    create OR REPLACE view EMP_VIEW as select * from table(get_emp());
    SELECT A.empno, A.empname, A.job, B.sal
    FROM EMP_VIEW A, EMP B
    WHERE A.empno = B.empno AND
          B.mgr = '7839'

    I am on DB 11.2.0.2 and have sparingly used pipelined table functions but am considering it for a project that has some fairly big (lots of rows) sized tables
    Which begs the question: WHY? What PROBLEM are you trying to solve and what makes you think using pipelined table functions is the best way to solve that problem?
    The lack of information about cardinality is the likely root of the degradation you noticed as already mentioned.
    But that should be a red flag about pipelined functions in general. PIPELINED functions hide virtually ALL KNOWLEDGE about the result set that is produced; cardinality is just the tip of the iceberg. Those functions pretty much say 'here is a result set' without ANY information about the number of rows (cardinality), distinct values for any columns, nullability of any columns, constraints that might apply to any columns (foreign key, primary key) and so on.
    If you are going to hide all of that information from Oracle that would normally be used to help optimize queries and select the appropriate execution plan you need to have a VERY good reason.
    The use of PIPELINED functions should be reserved for those use cases where ordinary SQL and PL/SQL cannot get the job done. That is they are a 'special case' solution.
    The classic use case for those functions is for the transform stage of ETL where multiple pipelined functions are chained together: one function feeds its rows to the next function which feeds its rows to another and so on. Each of those 'chained' functions is roughly analogous to a full table scan of the data that often does not need to be joined to other data except perhaps low volumn lookup tables where the data may even be cached.
    I suggest that any exploratory or prototyping work you do use standard relational tables until such point as you run into a problem whose solution might require PIPELINED functions to solve.

  • Join EQUI table with other table so as get address detail.

    Hi All,
    Can any one help me in the following case :
    I have to pass Equipment No. EQUNR on the selection screen and get Address detail (city, region, state, country, zipcode )
    now I am getting all this address related field in KNA1 table. Also I am able to join this two table with
    KNA1-KUNNR join EQUI-KUNDE as common field.
    Turning point
    when I am passing test data of Equipment No. EQUNR 60099204 I am not getting the address detail,
    because after passing EQUNR I am not getting KUNNR.
    So can any one please help me in joining EQUI table to some other table with field name so that I can get the address detail.
    Thanks

    Hi,
    The join between the table EQUI-kunde  join  KNA1-kunnr is ok but it not working for every value.
    Example :-
    In EQUI table when we pass  Equnr - 60099204 we need to get some value in KUNDE field, then only it will join to KNA1 table. But this is not happening, I am not getting value for KUNDE, hence join is not performing.
    So I need some other solution so that when we pass EQunr we can get the address details
    one thing more equnr  60099204 is having address detail, if we'll check IE03 (transaction by clicking address envelop)
    Thx.

  • How to create table view with reference table

    Hi experts,
    How to create table view with reference table in SE11, plz gve me stp by stp procedure.
    pints grnded for hlp.

    Hi
    Go to Tcode se11 choose view and enter the name and create a popup opens up choose database view option
    enter the description
    On the left hand side choose the table name.
    Click on view fields tab and choose your table fields.Here you can choose which fields you want in your view.
    Save and then activate.
    Hope this helps.
    Regards,
    Harish

  • Error binding table components with database tables

    Hi, when i try to bind table components with database tables y receive this error
    java.lang.NullPointerException
         at com.sun.sql.rowset.CachedRowSetXImpl.initMetaData(CachedRowSetXImpl.java:861)
         at com.sun.sql.rowset.CachedRowSetXImpl.getMetaData(CachedRowSetXImpl.java:2336)
         at com.sun.data.provider.impl.CachedRowSetDataProvider.getMetaData(CachedRowSetDataProvider.java:1317)
         at com.sun.data.provider.impl.CachedRowSetDataProvider.getFieldKeys(CachedRowSetDataProvider.java:489)
         at com.sun.rave.web.ui.component.table.TableRowGroupDesignState.resetTableColumns(TableRowGroupDesignState.java:261)
         at com.sun.rave.web.ui.component.table.TableRowGroupDesignState.setDataProviderBean(TableRowGroupDesignState.java:163)
         at com.sun.rave.web.ui.component.table.TableDesignState.setDataProviderBean(TableDesignState.java:250)
         at com.sun.rave.web.ui.component.TableDesignInfo.linkBeans(TableDesignInfo.java:162)
         at com.sun.rave.insync.models.FacesModel.linkBeans(FacesModel.java:1042)
         at com.sun.rave.designer.DndHandler.processLinks(DndHandler.java:2126)
         at com.sun.rave.designer.DndHandler.importBean(DndHandler.java:880)
         at com.sun.rave.designer.DndHandler.importItem(DndHandler.java:702)
         at com.sun.rave.designer.DndHandler.importDataDelayed(DndHandler.java:376)
         at com.sun.rave.designer.DndHandler.access$000(DndHandler.java:114)
    [catch] at com.sun.rave.designer.DndHandler$1.run(DndHandler.java:298)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

    There are a thing that I don't undertand. When I try to bind samples database table (Travel, for example) to table components, there are no errors. But when I try to bind table component with my remote postgresql database table, yes...the table component disappear and only a "Table" string is displayed....this error is because I use remote database?? Or because it's PostgreSQL??
    Thanks.

  • How to bind internal table values with RootUIElement(Table) from select Que

    Hello Friends,
           In my view Layout,there r two Input fields ,Submit button and Table... My concept is when user posting values in two input fields and clicking submit button means the result(more than one values) should be displayed in Table...
         I written coding also but i dont know to bind internal table values with Table... My code as follows,
    method onactionsearch .
       data:
         Node_Node_Flight                    type ref to If_Wd_Context_Node,
         Elem_Node_Flight                    type ref to If_Wd_Context_Element,
         Stru_Node_Flight                    type If_View1=>Element_Node_Flight ,
         itab TYPE STANDARD TABLE OF sflight.
    navigate from <CONTEXT> to <NODE_FLIGHT> via lead selection
       Node_Node_Flight = wd_Context->get_Child_Node( Name = IF_VIEW1=>wdctx_Node_Flight ).
    @TODO handle not set lead selection
       if ( Node_Node_Flight is initial ).
       endif.
    get element via lead selection
       Elem_Node_Flight = Node_Node_Flight->get_Element(  ).
    @TODO handle not set lead selection
       if ( Elem_Node_Flight is initial ).
       endif.
    alternative access  via index
    Elem_Node_Flight = Node_Node_Flight->get_Element( Index = 1 ).
    @TODO handle non existant child
    if ( Elem_Node_Flight is initial ).
    endif.
    get all declared attributes
       Elem_Node_Flight->get_Static_Attributes(
         importing
           Static_Attributes = Stru_Node_Flight ).
    select * from sflight into CORRESPONDING FIELDS OF TABLE itab
      WHERE carrid = Stru_Node_Flight-carrid and connid = Stru_Node_Flight-connid.
    Node_Node_Flight->bind_table( new_items = itab ).
    endmethod.
    Plz reply me asap...!

    Hi,
    What I understood from your coding is...
    * navigate from <CONTEXT> to <NODE_FLIGHT> via lead selection
    Node_Node_Flight = wd_Context->get_Child_Node( Name = IF_VIEW1=>wdctx_Node_Flight ).
    You are reading values from the above node and binding the values to the same node.Am i right?
    Did you take seperate context node for your input fields or binded the above context to the fields.If not then read the context attribute values which are binded to the carrid and connid then pass these values to select query.
    One more thing is select cardinality 1..n for node NODE_FLIGHT since you are displaying more than one record.
    Go through the some basic tutorials.Search in sdn you will it get.Already there is a tutorial in sdn which explains exactly what do you require.
    Go throgh this link
    Web Dynpro for ABAP: Tutorials for Beginners
    Web Dynpro for ABAP: Tutorials for Beginners [original link is broken]
    Edited by: suman kumar chinnam on Mar 26, 2009 10:50 AM

  • Translation of table entries with text table attached via SE63

    ZMRAREA(Custom) table has a text table(ZMRAREAT) attached to it.I want to copy the English text in all the other language codes for one of its text field.
    But when I try with the main object i.e. ZMRAREA,it throws "No object found" and when I try to translate using its text table( ZMRAREAT)
    it says "no text found in  source language"even though maintained in English.
    Unlike ZMRAREA, if I try with some other tables with no text table linkage then I could easily do the translation using the path :Translation>> ABAP OBJECTS >> Short Text>> A1 Application Texts >>  Tab TABLE >>CSKU<table name>  >> Edit  >> Edit >> Select the required record and proceed with the translation.
    Please give me the path for translation of text tables in SE63

    Hi
    Hope this will work for you.
    Reward if help.
    Transaction SE63 enables you to perform the following activities:
    - Call up an individual object to translate it directly
    - Call up a worklist to find and translate objects requiring translation and belonging to packages assigned to you
    - Define your translator settings to suit the way you want to work with the translation tools
    This helps in translating the text to different language.
    http://help.sap.com/saphelp_erp2005vp/helpdata/en/b4/54601d77f38e429ffad9e3e11c1b25/frameset.htm

  • How could i updated a table created with 5 tables.

    Hi everyone,
    This is my problem. I have five "tables" and each one contains one row and 7 columns. In the other hand, I have one table(Ireland1) that it retrieves the values of these 5 "tables" through of " insert into" statement.
    How would be I able to update of "Ireland1" data, when one of this "tables" (Remenber, I have 5 tables)  has changed?
    I have been searching information about this but  all my search has been fruitless.
    Thanks in advance,
    From Ireland

    Hi Eric,
    Thank you for your quick reply and solution. I have run your statement and appear this error:
    Msg 156, Level 15, State 1, Procedure Non_current_assets_Historic_View, Line 426
    Incorrect syntax near the keyword 'SELECT'.
    I dont know why this error appear
    I leave my Sript practically full
    USE Aerospace
    GO
    --TABLE NON-CURRENT ASSETS
    IF OBJECT_ID('Non_current_assets_Historic') IS NOT NULL
    DROP TABLE Non_current_assets_Historic
    GO
    CREATE TABLE Non_current_assets_Historic
    [IdCuenta] [float] NOT NULL,
    [NameCuenta] [nvarchar](255) NULL,
    Year_2006 decimal (14,2) NULL,
    Year_2007 decimal (14,2) NULL,
    Year_2008 decimal (14,2) NULL,
    Year_2009 decimal (14,2) NULL,
    Year_2010 decimal (14,2) NULL,
    Year_2011 decimal (14,2) NULL,
    Year_2012 decimal (14,2) NULL,
    Year_2013 decimal (14,2) NULL,
    Year_2014 decimal (14,2) NULL,
    Dif_2007_2006 decimal (14,2) NULL,
    Dif_2008_2007 decimal (14,2) NULL,
    Dif_2009_2008 decimal (14,2) NULL,
    Dif_2010_2009 decimal (14,2) NULL,
    Dif_2011_2010 decimal (14,2) NULL,
    Dif_2012_2011 decimal (14,2) NULL,
    Dif_2013_2012 decimal (14,2) NULL,
    Dif_2014_2013 decimal (14,2) NULL,
    AHP_2007_2006 decimal (14,2) NULL,
    AHP_2008_2007 decimal (14,2) NULL,
    AHP_2009_2008 decimal (14,2) NULL,
    AHP_2010_2009 decimal (14,2) NULL,
    AHP_2011_2010 decimal (14,2) NULL,
    AHP_2012_2011 decimal (14,2) NULL,
    AHP_2013_2012 decimal (14,2) NULL,
    AHP_2014_2013 decimal (14,2) NULL,
    GO
    ALTER TABLE Non_current_assets_Historic
    ADD CONSTRAINT PK_Non_current_assets_Historic PRIMARY KEY (IdCuenta)
    GO
    UPDATE Non_current_assets_Historic SET Year_2006=0 WHERE Year_2006 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2007=0 WHERE Year_2007 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2008=0 WHERE Year_2008 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2009=0 WHERE Year_2009 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2010=0 WHERE Year_2010 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2011=0 WHERE Year_2011 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2012=0 WHERE Year_2012 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2013=0 WHERE Year_2013 IS NULL
    UPDATE Non_current_assets_Historic SET Year_2014=0 WHERE Year_2014 IS NULL
    GO
    INSERT INTO Non_current_assets_Historic
    SELECT *
    FROM Property_plant_equipment_Historic
    INSERT INTO Non_current_assets_Historic
    SELECT *
    FROM Intangible_assets_Historic
    INSERT INTO Non_current_assets_Historic
    SELECT *
    FROM Available_financial_assets_Historic
    INSERT INTO Non_current_assets_Historic
    SELECT *
    FROM Deferred_tax_assets_Historic
    INSERT INTO Non_current_assets_Historic
    SELECT *
    FROM Deposits_restricted_12M_Historic
    GO
    --SUMATORIO YEAR 2006
    Declare @Cantidad20061 decimal (14,2)
    Declare @Cantidad20062 decimal (14,2)
    Declare @Cantidad20063 decimal (14,2)
    Declare @Cantidad20064 decimal (14,2)
    Declare @Cantidad20065 decimal (14,2)
    Select @Cantidad20061 = Year_2006 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad20062 = Year_2006 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad20063 = Year_2006 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad20064 = Year_2006 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad20065 = Year_2006 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2007
    Declare @Cantidad20071 decimal (14,2)
    Declare @Cantidad20072 decimal (14,2)
    Declare @Cantidad20073 decimal (14,2)
    Declare @Cantidad20074 decimal (14,2)
    Declare @Cantidad20075 decimal (14,2)
    Select @Cantidad20071 = Year_2007 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad20072 = Year_2007 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad20073 = Year_2007 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad20074 = Year_2007 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad20075 = Year_2007 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2008
    Declare @Cantidad20081 decimal (14,2)
    Declare @Cantidad20082 decimal (14,2)
    Declare @Cantidad20083 decimal (14,2)
    Declare @Cantidad20084 decimal (14,2)
    Declare @Cantidad20085 decimal (14,2)
    Select @Cantidad20081 = Year_2008 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad20082 = Year_2008 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad20083 = Year_2008 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad20084 = Year_2008 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad20085 = Year_2008 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2009
    Declare @Cantidad20091 decimal (14,2)
    Declare @Cantidad20092 decimal (14,2)
    Declare @Cantidad20093 decimal (14,2)
    Declare @Cantidad20094 decimal (14,2)
    Declare @Cantidad20095 decimal (14,2)
    Select @Cantidad20091 = Year_2009 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad20092 = Year_2009 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad20093 = Year_2009 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad20094 = Year_2009 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad20095 = Year_2009 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2010
    Declare @Cantidad200101 decimal (14,2)
    Declare @Cantidad200102 decimal (14,2)
    Declare @Cantidad200103 decimal (14,2)
    Declare @Cantidad200104 decimal (14,2)
    Declare @Cantidad200105 decimal (14,2)
    Select @Cantidad200101 = Year_2010 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad200102 = Year_2010 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad200103 = Year_2010 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad200104 = Year_2010 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad200105 = Year_2010 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2011
    Declare @Cantidad200111 decimal (14,2)
    Declare @Cantidad200112 decimal (14,2)
    Declare @Cantidad200113 decimal (14,2)
    Declare @Cantidad200114 decimal (14,2)
    Declare @Cantidad200115 decimal (14,2)
    Select @Cantidad200111 = Year_2011 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad200112 = Year_2011 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad200113 = Year_2011 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad200114 = Year_2011 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad200115 = Year_2011 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2012
    Declare @Cantidad200121 decimal (14,2)
    Declare @Cantidad200122 decimal (14,2)
    Declare @Cantidad200123 decimal (14,2)
    Declare @Cantidad200124 decimal (14,2)
    Declare @Cantidad200125 decimal (14,2)
    Select @Cantidad200121 = Year_2012 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad200122 = Year_2012 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad200123 = Year_2012 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad200124 = Year_2012 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad200125 = Year_2012 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2013
    Declare @Cantidad200131 decimal (14,2)
    Declare @Cantidad200132 decimal (14,2)
    Declare @Cantidad200133 decimal (14,2)
    Declare @Cantidad200134 decimal (14,2)
    Declare @Cantidad200135 decimal (14,2)
    Select @Cantidad200131 = Year_2013 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad200132 = Year_2013 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad200133 = Year_2013 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad200134 = Year_2013 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad200135 = Year_2013 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO YEAR 2014
    Declare @Cantidad200141 decimal (14,2)
    Declare @Cantidad200142 decimal (14,2)
    Declare @Cantidad200143 decimal (14,2)
    Declare @Cantidad200144 decimal (14,2)
    Declare @Cantidad200145 decimal (14,2)
    Select @Cantidad200141 = Year_2014 from Non_current_assets_Historic where IdCuenta ='7'
    Select @Cantidad200142 = Year_2014 from Non_current_assets_Historic where IdCuenta ='8'
    Select @Cantidad200143 = Year_2014 from Non_current_assets_Historic where IdCuenta ='9'
    Select @Cantidad200144 = Year_2014 from Non_current_assets_Historic where IdCuenta ='10'
    Select @Cantidad200145 = Year_2014 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2007_2006
    Declare @DIF_2007_20061 decimal (14,2)
    Declare @DIF_2007_20062 decimal (14,2)
    Declare @DIF_2007_20063 decimal (14,2)
    Declare @DIF_2007_20064 decimal (14,2)
    Declare @DIF_2007_20065 decimal (14,2)
    Select @DIF_2007_20061 = Dif_2007_2006 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2007_20062 = Dif_2007_2006 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2007_20063 = Dif_2007_2006 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2007_20064 = Dif_2007_2006 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2007_20065 = Dif_2007_2006 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2008_2007
    Declare @DIF_2008_20071 decimal (14,2)
    Declare @DIF_2008_20072 decimal (14,2)
    Declare @DIF_2008_20073 decimal (14,2)
    Declare @DIF_2008_20074 decimal (14,2)
    Declare @DIF_2008_20075 decimal (14,2)
    Select @DIF_2008_20071 = Dif_2008_2007 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2008_20072 = Dif_2008_2007 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2008_20073 = Dif_2008_2007 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2008_20074 = Dif_2008_2007 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2008_20075 = Dif_2008_2007 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2009_2008
    Declare @DIF_2009_20081 decimal (14,2)
    Declare @DIF_2009_20082 decimal (14,2)
    Declare @DIF_2009_20083 decimal (14,2)
    Declare @DIF_2009_20084 decimal (14,2)
    Declare @DIF_2009_20085 decimal (14,2)
    Select @DIF_2009_20081 = Dif_2009_2008 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2009_20082 = Dif_2009_2008 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2009_20083 = Dif_2009_2008 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2009_20084 = Dif_2009_2008 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2009_20085 = Dif_2009_2008 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2010_2009
    Declare @DIF_2010_20091 decimal (14,2)
    Declare @DIF_2010_20092 decimal (14,2)
    Declare @DIF_2010_20093 decimal (14,2)
    Declare @DIF_2010_20094 decimal (14,2)
    Declare @DIF_2010_20095 decimal (14,2)
    Select @DIF_2010_20091 = Dif_2010_2009 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2010_20092 = Dif_2010_2009 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2010_20093 = Dif_2010_2009 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2010_20094 = Dif_2010_2009 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2010_20095 = Dif_2010_2009 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2011_2010
    Declare @DIF_2011_20101 decimal (14,2)
    Declare @DIF_2011_20102 decimal (14,2)
    Declare @DIF_2011_20103 decimal (14,2)
    Declare @DIF_2011_20104 decimal (14,2)
    Declare @DIF_2011_20105 decimal (14,2)
    Select @DIF_2011_20101 = Dif_2011_2010 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2011_20102 = Dif_2011_2010 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2011_20103 = Dif_2011_2010 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2011_20104 = Dif_2011_2010 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2011_20105 = Dif_2011_2010 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2012_2011
    Declare @DIF_2012_20111 decimal (14,2)
    Declare @DIF_2012_20112 decimal (14,2)
    Declare @DIF_2012_20113 decimal (14,2)
    Declare @DIF_2012_20114 decimal (14,2)
    Declare @DIF_2012_20115 decimal (14,2)
    Select @DIF_2012_20111 = Dif_2012_2011 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2012_20112 = Dif_2012_2011 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2012_20113 = Dif_2012_2011 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2012_20114 = Dif_2012_2011 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2012_20115 = Dif_2012_2011 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2013_2012
    Declare @DIF_2013_20121 decimal (14,2)
    Declare @DIF_2013_20122 decimal (14,2)
    Declare @DIF_2013_20123 decimal (14,2)
    Declare @DIF_2013_20124 decimal (14,2)
    Declare @DIF_2013_20125 decimal (14,2)
    Select @DIF_2013_20121 = Dif_2013_2012 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2013_20122 = Dif_2013_2012 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2013_20123 = Dif_2013_2012 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2013_20124 = Dif_2013_2012 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2013_20125 = Dif_2013_2012 from Non_current_assets_Historic where IdCuenta ='11'
    --SUMATORIO DIF_2014_2013
    Declare @DIF_2014_20131 decimal (14,2)
    Declare @DIF_2014_20132 decimal (14,2)
    Declare @DIF_2014_20133 decimal (14,2)
    Declare @DIF_2014_20134 decimal (14,2)
    Declare @DIF_2014_20135 decimal (14,2)
    Select @DIF_2014_20131 = Dif_2014_2013 from Non_current_assets_Historic where IdCuenta ='7'
    Select @DIF_2014_20132 = Dif_2014_2013 from Non_current_assets_Historic where IdCuenta ='8'
    Select @DIF_2014_20133 = Dif_2014_2013 from Non_current_assets_Historic where IdCuenta ='9'
    Select @DIF_2014_20134 = Dif_2014_2013 from Non_current_assets_Historic where IdCuenta ='10'
    Select @DIF_2014_20135 = Dif_2014_2013 from Non_current_assets_Historic where IdCuenta ='11'
    insert into Non_current_assets_Historic (IdCuenta,NameCuenta,Year_2006 , Year_2007,Year_2008 ,Year_2009 ,Year_2010,Year_2011 ,Year_2012 ,Year_2013 ,
    Year_2014,Dif_2007_2006,Dif_2008_2007, Dif_2009_2008, Dif_2010_2009,Dif_2011_2010,Dif_2012_2011,Dif_2013_2012,Dif_2014_2013,
    AHP_2007_2006, AHP_2008_2007 , AHP_2009_2008, AHP_2010_2009, AHP_2011_2010, AHP_2012_2011 , AHP_2013_2012,AHP_2014_2013 )
    Values (1, 'Non-current assets', NULL,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll),
    (19, '', NULL,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll,NUll),
    (20, 'Total Non-current assets',
    --Year_2006
    (@Cantidad20061 +@Cantidad20062 +@Cantidad20063 +@Cantidad20064 +@Cantidad20065),
    --Year_2007
    (@Cantidad20071+ @Cantidad20072 + @Cantidad20073+ @Cantidad20074+ @Cantidad20075),
    --Year_2008
    (@Cantidad20081 + @Cantidad20082 + @Cantidad20083 + @Cantidad20084 + @Cantidad20085),
    --Year_2009
    (@Cantidad20091 + @Cantidad20092 + @Cantidad20093+ @Cantidad20094 + @Cantidad20095),
    --Year_2010
    (@Cantidad200101 + @Cantidad200102 + @Cantidad200103 + @Cantidad200104 + @Cantidad200105),
    --Year_2011
    (@Cantidad200111 + @Cantidad200112 + @Cantidad200113 + @Cantidad200114 + @Cantidad200115),
    --Year_2012
    (@Cantidad200121 + @Cantidad200122 + @Cantidad200123 +@Cantidad200124 + @Cantidad200125),
    --Year_2013
    (@Cantidad200131 + @Cantidad200132 +@Cantidad200133 + @Cantidad200134 + @Cantidad200135),
    --Year_2014
    (@Cantidad200141 + @Cantidad200142 + @Cantidad200143 + @Cantidad200144 + @Cantidad200145),
    --Diferencia Numeria 2007-2006
    (@DIF_2007_20061 + @DIF_2007_20062 + @DIF_2007_20063 + @DIF_2007_20064 + @DIF_2007_20065),
    --Diferencia Numeria 2008-2007
    (@DIF_2008_20071 + @DIF_2008_20072 + @DIF_2008_20073 + @DIF_2008_20074 + @DIF_2008_20075),
    --Diferencia Numeria 2009-2008
    (@DIF_2009_20081 + @DIF_2009_20082 + @DIF_2009_20083 + @DIF_2009_20084 + @DIF_2009_20085 ),
    --Diferencia Numeria 2010-2009
    (@DIF_2010_20091 + @DIF_2010_20092 + @DIF_2010_20093 + @DIF_2010_20094 + @DIF_2010_20095),
    --Diferencia Numeria 2011-2006
    (@DIF_2011_20101 + @DIF_2011_20102 + @DIF_2011_20103 +@DIF_2011_20104 + @DIF_2011_20105 ),
    --Diferencia Numeria 2012-2011
    (@DIF_2012_20111+@DIF_2012_20112+@DIF_2012_20113+@DIF_2012_20114+@DIF_2012_20115),
    --Diferencia Numeria 2013-2012
    (@DIF_2013_20121 + @DIF_2013_20122 +@DIF_2013_20123 +@DIF_2013_20124 + @DIF_2013_20125),
    --Diferencia Numeria 2014-2013
    (@DIF_2014_20131+@DIF_2014_20132+@DIF_2014_20133+@DIF_2014_20134+@DIF_2014_20135),
    --Diferencia Porcentual 2007-2006
    (@DIF_2007_20061+@DIF_2007_20062+@DIF_2007_20063+@DIF_2007_20064+@DIF_2007_20065)/(@Cantidad20061 +@Cantidad20062 +@Cantidad20063 +@Cantidad20064 +@Cantidad20065),
    --Diferencia Porcentual 2008-2007
    (@DIF_2008_20071 + @DIF_2008_20072 + @DIF_2008_20073 + @DIF_2008_20074 + @DIF_2008_20075)/(@Cantidad20071+ @Cantidad20072 + @Cantidad20073+ @Cantidad20074+ @Cantidad20075),
    --Diferencia Porcentual 2009-2008
    (@DIF_2009_20081 + @DIF_2009_20082 + @DIF_2009_20083 + @DIF_2009_20084 + @DIF_2009_20085 )/(@Cantidad20081 + @Cantidad20082 + @Cantidad20083 + @Cantidad20084 + @Cantidad20085),
    --Diferencia Porcentual 2010-2009
    (@DIF_2010_20091 + @DIF_2010_20092 + @DIF_2010_20093 + @DIF_2010_20094 + @DIF_2010_20095)/(@Cantidad20091 + @Cantidad20092 + @Cantidad20093+ @Cantidad20094 + @Cantidad20095),
    --Diferencia Porcentual 2011-2010
    (@DIF_2011_20101 + @DIF_2011_20102 + @DIF_2011_20103 +@DIF_2011_20104 + @DIF_2011_20105)/(@Cantidad200101 + @Cantidad200102 + @Cantidad200103 + @Cantidad200104 + @Cantidad200105),
    --Diferencia Porcentual 2012-2011
    (@DIF_2012_20111+@DIF_2012_20112+@DIF_2012_20113+@DIF_2012_20114+@DIF_2012_20115)/(@Cantidad200111 + @Cantidad200112 + @Cantidad200113 + @Cantidad200114 + @Cantidad200115),
    --Diferencia Porcentual 2013-2012
    (@DIF_2013_20121 + @DIF_2013_20122 +@DIF_2013_20123 +@DIF_2013_20124 + @DIF_2013_20125)/(@Cantidad200121 + @Cantidad200122 + @Cantidad200123 +@Cantidad200124 + @Cantidad200125),
    --Diferencia Porcentual 2014-2013
    (@DIF_2014_20131+@DIF_2014_20132+@DIF_2014_20133+@DIF_2014_20134+@DIF_2014_20135)/(@Cantidad200131 + @Cantidad200132 +@Cantidad200133 + @Cantidad200134 + @Cantidad200135))
    GO
    SELECT IdCuenta ,NameCuenta ,Year_2006 ,Year_2007 ,Year_2008 ,Year_2009 ,Year_2010 ,Year_2011 ,Year_2012 , Year_2013 ,Year_2014
    FROM Non_current_assets_Historic
    Maybe the error is in the design
    of this table
    Regards
    Francisco
    I work with SQL 2014 Management Studio

  • Records getting multiplied  by a factor of 3 when joining with other table

    When i query a table association_1 records for a particular network element i get 7 records
    but join it with rtts_association table to get the rtts_no i m getting 21 records.....
    the problems is ... 7 records are getting multiplied by a factor of 3 resulting in 21 records ....
    how can i avoid these extra records that appear in the second query
    SQL> select raised,cleared from association_1 where ne ='30434000/1MU';
    RAISED               CLEARED
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26
    SQL> select a.raised,a.cleared,b.rtts from association_1 a, rtts_association b where a.ne=b.ne and a.ne='30434000/1MU';
    RAISED               CLEARED                    RTTS
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1490980
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487697
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487649
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1490980
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1487697
    12-FEB-2011 06:27:18 12-FEB-2011 06:29:51    1487649
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1490980
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1487697
    21-FEB-2011 21:36:44 22-FEB-2011 10:23:06    1487649
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1490980
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1487697
    RAISED               CLEARED                    RTTS
    23-FEB-2011 01:08:44 23-FEB-2011 06:56:53    1487649
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1490980
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1487697
    23-FEB-2011 17:06:16 23-FEB-2011 19:55:19    1487649
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1490980
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1487697
    23-FEB-2011 20:37:22 23-FEB-2011 23:01:21    1487649
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1490980
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1487697
    24-FEB-2011 00:33:17 24-FEB-2011 02:03:26    1487649
    21 rows selected.

    For every combination of raised & cleared columns in "association_1" table, there are 3 records in the "rtts_association" table with different values for "RTTS" as below:
    Association_1:
    RAISED               CLEARED
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15
    rtts_association
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1490980
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487697
    03-FEB-2011 22:03:10 03-FEB-2011 22:06:15    1487649Hence, evidently you wil get 7 (association_1) * 3 (rtts_association) in your output. If you want only one record in the output, you may need to pick any one of the values of RTTS from the 3 different values based on a pre-defined condition (e.g. record corresponding to lowest or highest value of RTTS)
    Cheers --

  • Parse comma separated value and map with other table to get Name and change it back to comma separate.

    Hi,
    I have one existing view(with around 15 fields), in which I have to add few more fields from table called PI.
    Now these fields have values like (55C4444F-D83B-4F96-A011-367A3755BA6C , F52388E2-485B-49DF-8534-FDF46D23F59E , 722432E1-F063-4CBD-B83D-1B97836E82953) 3 values comma separated.(Sometimes only one value and sometimes 4 or 5 or 7-8 depend on user has entered
    on web page)
    Also I have another table called PHA and this tables has 2 fields Values and Name so I have to map this two tables based on VALUES fields and get Name from this PHA table and show in view and that also Comma separated.
    So basically I have to Parse the PI table's Values field 1st, map it with PHA table to get Name and then Make it comma separated in that existing view.
    To make fields comma separate I used below query,
    (SELECT DISTINCT SUBSTRING
                SELECT ','+ PI.[Name]  AS [text()]
                FROM [DB].[dbo].[Table] PHA1
    Inner Join  [DB].[dbo].[Table] PI
    ON PHA.[Value] = PI.[VALUE]
                WHERE PHA1.PId =PHA2.PId and PHA1.CId = PHA2.CId
                ORDER BY PHA1.PId
                For XML PATH ('')
            ), 2, 1000) 
    FROM [DB].[dbo].[Table] PHA2
    Inner Join [cSharpSite_profiles].[dbo].[PetAllergies] PA
    Inner Join  [DB].[dbo].[Table] PI
    ON PHA.[Value] = PI.[VALUE]
    ) [Name]
    Vicky

    Wait, this sounds wrong. You have a view where you group values into a comma-separated list. While that surely will make some purists cringe, I can see that it makes sense from a presentation perspective.
    But if you want to use these concatenated values as atomic values again, you should go back to the base tables and them from there. Building views on views may sometimes be a good idea, but if you are too keen on reuse you can cause a performance disaster.
    So do it right from the beginning.
    Erland Sommarskog, SQL Server MVP, [email protected]

  • Case statement resulting into Left outer join with other tables

    Hi All ,
    I am facing a stuation where a Case statement on one of the logical columns in Answers is resulting into a left outer join with a table in the query.
    If we remove the case stmt, the table is not being acessed.
    The case stmt is a simple one and no other logical column is being accessed in the case stmt.
    Please advice .
    Thanks.

    Hi Sai,
    No ..we dont have any left outer join ...its just that I am selecting measure from F1 which has a confimred dimension D1 with F2.Now when I dont have case stmt on measure from F1(Case stmt is something like : CASE WHEN "- P table"."P Column" = 'Y' THEN 'Right' ELSE 'Wrong' END), then it doesnt query F2.
    However as soon as I introduce the case stmt ,the query creates a left outer join with F2.
    Thanks.

  • Can ui:table deal with large table?

    I have found h:dataTable can do pagination because it's data source is just a DataModel. But ui:table's datasouce is a data provider which looks some complex and confused.
    I have a large table and I want to load the data on-demand . So I try to implement a provider. But soon I found that the ui:table may be load all data from provider always.
    In TableRowGroup.java, there are many code such as:
    provider.getRowKeys(rowCount, null);
    null will let provider load all data.
    So ui:table can NOT deal with large table!?
    thx.
    fan

    But ui:table just uses TableDataProvider interface.TableData provider is a wrapper for the CachedRowSet
    There are two layers between the UI:Table comonent and the database table: the RowSet layer and the Data Provider layer. The RowSet layer makes the connection to the database, executes the queries, and manages the result set. The Data Provider layer provides a common interface for accessing many types of data, from rowsets, to Array objects, to Enterprise JavaBeans objects.
    Typically, the only time that you work with the RowSet object is when you need to set query parameters. In most other cases, you should use the Data Provider to access and manipulate the data.
    What can a CachedRowSet (or CachedRowSetprovider?)
    do?Check out the API that I pointed you to to see what you can do with a CachedRowSet
    Does the Table cache the data itself?
    Maybe this way is convenient for filter and order?
    Thx.I do not know the answers to these questions.

  • Lock row in 1 table while update other tables

    Gurus,
    I want to read 1 table. If the date is less than today, I want to update 4 other tables. I only want to do this update once a day.
    While the 4 other tables are being updated, I want the other web users to pause for the update while this procedure runs.
    Is there a better way to do this?
    TIA
    Steve42
    Here is what I have:
    CREATE OR REPLACE PROCEDURE TEST_TODAY2 AS
    -- to create the table
    -- create table test_today(updated_date date);
    -- insert into test_today(updated_date) values (sysdate-1);
    -- select * from test_today;
        cursor daily_update_cur is
        select updated_date from test_today
          for update of updated_date;
       last_updated_date date;
    BEGIN
      NULL;
        open daily_update_cur;
        fetch daily_update_cur into last_updated_date;
        IF  trunc(last_updated_date) < trunc(sysdate) THEN
           -- update 4 other tables
           -- After those are updated,  update test_today
           dbms_output.put_line('After updating tables');
           update test_today set updated_date=sysdate;
        ELSE
           dbms_output.put_line('Tables already up to date');
           null;
        END IF;
        execute immediate 'commit';
        close daily_update_cur;
    END TEST_TODAY2;Edited by: BluShadow on 15-Oct-2012 14:22
    Please use {noformat}{noformat} tags before and after your code as described in the FAQ: {message:id=9360002}.
    I've corrected it this time for you.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    Steve,
    I just checked your requirements and program. It seems fine.
    You can modify something on this. As below part is not required as it ll never happen.. :)
        ELSE
           dbms_output.put_line('Tables already up to date');
           null;
        END IF;
    /* execute immediate 'commit';  -- No need to write in dynamic sql as its not a DDL statement */
    commit;Sorry for going out of topic.
    Since I'm a NEWBIE, I just wanted to make sure that this would work before
    we roll this out to LIVE PRODUCTION.Newbie is defined on the basis of the date you joined/registered. It never asked for your experience or a screening while signing up.
    Better you can have an other idea to filter out people by their replies/sense with quality/weight of statements as newbies or experts ! .. :)
    Thanks!

  • How to del table ref in other table .

    Dear all,
                i was deleteing a table which was refrenced in other table , so it was asking me to del the fk then delete the table.
    is there any way exists, to del the table and its relation used in other tables.
    yours sincerley

    You can try one of the solutions provided in this thread:
    http://stackoverflow.com/questions/15107238/how-can-i-drop-a-table-if-there-is-a-foreign-key-constraint-in-sql-server

  • Removal of data from 1 table after comparing with other table

    Hi,
    I have 2 table. Both have same primary key i.e. WO_ID. 1st table wrk_ord have no redundant data and the 2nd table wo_audit have few redundant data. Both table are related with WO_ID. Now I want to remove the redundant data from table wo_audit so that the uniq WO would be same in both the table. both the table are very huge. WO_ID table have 31million of record. I ran query
    delete from wo_audit where wo_id not in (select wo_id from wrk_ord);
    this query throw an error ora-01555. I just want to know the how can optimize this query.
    Thanks.

    Hi,
    delete from wo_audit where wo_id not in (select wo_id from wrk_ord);AFAIk, you not removing redundant data, but you are removing the data which does not exists in wrk_ord. Try to check things from business perspective.
    Tune the value of the UNDO_RETENTION parameter, check the the below one
    select max(maxquerylen) from v$undostat;
    - Pavan Kumar N
    Edited by: Pavan Kumar on Apr 8, 2011 1:36 PM

Maybe you are looking for