Update with join/subquery

I have 2 tables
tblA(aID, aSeq, aname, aLname)
tblB(bSeq, bname, bLname)
I need to update table tblA to set aSeq where the name and Lname match with tblB. Something like
update zA A
set A.aSeq =
select B.bSeq
from zB B
where UPPER(B.bname) = UPPER(A.aname)
and UPPER(B.blname) = UPPER(A.alname)
What am I doing wrong? Why do I get the error - ORA-01427: single-row subquery returns more than one row

based on above scenario (tblA => proposal tblB => personnel)
select rp.prop_id || '| ' || UPPER(rp.prodir_fn) || '| ' || UPPER(rp.prodir_ln)
from proposal rp
where exists(
select p.piid ---------------------------------------------------get matching names from personnel
from personnel p
where UPPER(rp.prodir_fn) = UPPER(p.fname)
and UPPER(rp.prodir_ln) = UPPER(p.lname)
and EXISTS
( select UPPER(q.fname), UPPER(q.lname)     ------------ get matching names of single person that is drop
from personnel q--------------------------------------------- peron names who have same first and last name different id
where UPPER(q.fname) = UPPER(p.fname)
and UPPER(q.lname) = UPPER(p.lname)
group by UPPER(q.fname), UPPER(q.lname)
having count(*) = 1
gives me 3535 matching records
but
my update still fails, Please guide
UPDATE proposal rp
set rp.pi = (
select p.piid
from personnel p
where UPPER(rp.prodir_fn) = UPPER(p.fname)
and UPPER(rp.prodir_ln) = UPPER(p.lname)
and EXISTS
( select UPPER(q.fname), UPPER(q.lname)
from personnel q
where UPPER(q.fname) = UPPER(p.fname)
and UPPER(q.lname) = UPPER(p.lname)
group by UPPER(q.fname), UPPER(q.lname)
having count(*) = 1
;

Similar Messages

  • Oracle Syntax for Update with Join

    Can anyone help with the Oracle Syntax on and update that includes a join?
    This is what I've got:
    Update
    (SELECT a.DOCUMENT_NO
    From DOCUMENT_CONTROL a, DOCNOTEST b
    where a.DOCUMENT_NO = b.DOCUMENT_NO)
    set a.PATH = NULL
    Everything I try leads to another error message. With the current code I'm getting the error message: ORA-00971 a.path invalid identifier.
    I am much more familiar with SQL Server (if you can't tell :) This is the way I would write the above in SQL Server.
    UPDATE DOCUMENT_CONTROL
    Set [Path] = ''
    FROM DOCUMENT_CONTROL
    INNER JOIN DOCNOTEST
    ON DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
    where DOCUMENT_CONTROL.DOCUMENT_NO=DOCNOTEST.DOCUMENT_NO
    Does anyone have any advice for me? Thanks in advance

    Alternate syntax since it seems you're not able to update the join...
    update DOCUMENT_CONTROL a
    set
       a.path = null
    where a.path is not null
    and exists
       select null
       from DOCNOTEST b
       where  a.DOCUMENT_NO = b.DOCUMENT_NO
    );

  • Update with join and group by

    Hello All,
    I'm trying to update several colums of a table from a inner join query.
    First a retrieve the rows afected and the values that I need for the update (I call this subquery ED_Query).
    It's important to note that this subquery has a group by and and having clause.
    My first attemp (using the query that work in SQL Server query) fails:
    SQL> update ED_Update
    2 set ED_Update.dtHoraInicioReal = ED_Query.dtHoraInicioReal,
    3 ED_Update.dtHoraFinReal = ED_Query.dtHoraFinReal,
    4 ED_Update.fPorcentajeRealizado = ED_Query.fPorcentajeRealizado
    5 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED_Update
    6 inner join (
    7 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    8 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    9 MAX(HPP.iOrden) as iOrdenUltimaParada,
    10 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    11 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    12 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado
    13 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    14 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    15 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    16 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    17 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    18 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal
    19 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    20 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
    21 ) ED_Query
    22 on ED_Update.iIdExpedicionDiaria = ED_Query.iIdExpedicionDiaria;
    ERROR at line 5:
    ORA-00933: SQL command not properly ended
    The subquery (ED_Query) work fine in Oracle, so I suspect that the problems are when I mix it with the update clause.
    SQL> select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    2 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    3 MAX(HPP.iOrden) as iOrdenUltimaParada,
    4 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    5 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    6 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    7 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    8 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    9 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    10 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    11 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    12 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    13 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal, ED.dtHoraFinReal, ED.fPorcentajeRealizado
    14 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    15 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal);
    IIDEXPEDICION IIDEXPEDICIONDIARIA INUMPARADAS IORDENULTIMAPARADA DTHORAINI
    DTHORAFIN FPORCENTAJEREALIZADO ED_DTHORA ED_DTHORA ED_FPORCENTAJEREALIZADO
    -131076 5662 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    -131076 5663 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    -131076 5664 406 15-JAN-13
    15-JAN-13 15-JAN-13 15-JAN-13 0
    After reading this forum, I change the query and try the next one:
    SQL> UPDATE
    2 (
    3 select distinct ED.iIdExpedicion, ED.iIdExpedicionDiaria,
    4 MAX(PT.iOrdenEnTrayecto) + 1 as iNumParadas,
    5 MAX(HPP.iOrden) as iOrdenUltimaParada,
    6 MIN(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60)) as dtHoraInicioReal,
    7 MAX(dtHora_LlegadaReal) as dtHoraFinReal,
    8 100 * cast ((MAX(HPP.iOrden) + 1) as float) / cast ((MAX(PT.iOrdenEnTrayecto) + 1) as float) as fPorcentajeRealizado,
    9 ED.dtHoraInicioReal as ED_dtHoraInicioReal, ED.dtHoraFinReal as ED_dtHoraFinReal, ED.fPorcentajeRealizado as ED_fPorcentajeRealizado
    10 from HISTORICOS_AVANZA.HSAE_HIS_EXPEDICIONDIARIA ED
    11 left join HISTORICOS_AVANZA.HSAE_HIS_HORAPASOPARADA HPP
    12 on ED.iIdExpedicion = HPP.iIdExpedicion and ED.dtJornada = HPP.dtJornada
    13 left join AVANZA.SAE_URB_PARADASTRAYECTO PT on ED.iIdLinea = PT.iIdLinea and ED.iIdTrayecto = PT.iIdTrayecto
    14 where ED.dtJornada = TO_DATE('14/01/2013', 'DD/MM/YYYY') and ED.iIdExpedicion in (-131076)
    15 group by ED.iIdExpedicion, ED.iIdExpedicionDiaria, ED.dtHoraInicioReal,ED.dtHoraFinReal, ED.fPorcentajeRealizado
    16 having ED.dtHoraInicioReal <> min(dtHora_LlegadaReal + iTiempoEnParada/(24*60*60))
    17 or ED.dtHoraFinReal <> max(dtHora_LlegadaReal)
    18 )
    19 SET ED_dtHoraInicioReal = dtHoraInicioReal,
    20 ED_dtHoraFinReal = dtHoraFinReal,
    21 ED_fPorcentajeRealizado = fPorcentajeRealizado;
    ERROR at line 2:
    ORA-01732: data manipulation operation not legal on this view
    Some help?
    Thanl in advance.
    Edited by: 984483 on 28-ene-2013 1:48

    Thanks for your answer. I tried to rewrite my question.
    SQL> select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.3.0 - Production
    PL/SQL Release 9.2.0.3.0 - Production
    CORE 9.2.0.3.0 Production
    TNS for 32-bit Windows: Version 9.2.0.3.0 - Production
    NLSRTL Version 9.2.0.3.0 - Production
    I have 2 tables. I like to update one of them (ED_Update) with the data from the another one (ED_Query).
    This example is equivalent:
    create table ED_Query (id number,
         date01 date,
    number01 number)
    insert into ED_Query values (1, to_date('01/01/2013','DD/MM/YYYY'), 10);
    insert into ED_Query values (2, to_date('01/01/2013','DD/MM/YYYY'), 20);
    insert into ED_Query values (3, to_date('01/01/2013','DD/MM/YYYY'), 30);
    insert into ED_Query values (4, to_date('02/01/2013','DD/MM/YYYY'), 40);
    insert into ED_Query values (5, to_date('03/01/2013','DD/MM/YYYY'), 50);
    create table ED_Update (date01 date,
              numberMax number,
              numberSum number)
    insert into ED_Update values (to_date('01/01/2013','DD/MM/YYYY'), 0, 0);
    insert into ED_Update values (to_date('02/01/2013','DD/MM/YYYY'), 0, 0);
    insert into ED_Update values (to_date('03/01/2013','DD/MM/YYYY'), 0, 0);     
    The next update query fails with ORA-00933: SQL command not properly ended.
    update ED_Update
    set ED_Update.date01 = ED_Query.date01,
         ED_Update.numberMax = ED_Query.numberMax,
         ED_Update.numberSum = ED_Query.numberSum
    inner join
         select date01, max (number01) as numberMax, sum(number01) as numberSum
         from ED_Query
         where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
         group by date01
    ) ED_Query
    on ED_Update.date01 = ED_Query.date01
    I think the problem is in the update clause because the next query work:
    select * from
    ED_Update
    inner join
         select date01, max (number01) as numberMax, sum(number01) as numberSum
         from ED_Query
         where date01 = TO_DATE('01/01/2013', 'DD/MM/YYYY')
         group by date01
    ) ED_Query
    on ED_Update.date01 = ED_Query.date01
    Thank in advance.

  • Update with join

    Hello Everybody
    I have 3 tables in a maxdb 7.6 database
    rbarbeitsplanpos key=rbarbeitsplanposid column gewichtung,...
    rbaplposausf key=rbaplposausfid columns rbarbeitsplanposid,...
    rbqspruefpos key=rbqspruefposid columns rbaplposausfid,gewichtung,...
    Now i want to update gewichtung in rbqspruefpos with the value of gewichtung in the corresponding record in rbarbeitsplanpos.
    The way to find the correct value is:
    From rbqspruefpos with rbaplposausfid into rbaplposausf  
    From rbaplposausf with rbarbeitsplanposid to rbarbeitsplanpos
    I found this hit:
    A simple example of the power of including joins in an Update Statement:
    Update Tbl1 set tbl1.field1=tbl2.field2*.10,
    from Tbl1 join tbl2 on tbl1.PKfield=tbl2.tbl1FK
    This will update all the joined rows in tbl1 to 10% of the values in tbl2.
    I code:
    update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
    from rbqspruefpos
    join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
    join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    General error;-5016 POS(73) Missing delimiter: =
    This one works without errors:
    update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
    join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
    but all rbqspruefpos.gewichtung are filled with the same value?
    The first value found in rbarbeitsplanpos.
    Any help welcomed
    Best regards
    Albert

    > I code:
    > update rbqspruefpos set gewichtung =  rbarbeitsplanpos.gewichtung,
    > from rbqspruefpos
    > join  rbaplposausf on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid
    > join rbarbeitsplanpos on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    >
    >  General error;-5016 POS(73) Missing delimiter: =
    >
    >
    > This one works without errors:
    > update rbqspruefpos set gewichtung = (select rbarbeitsplanpos.gewichtung  from rbarbeitsplanpos
    > join  rbaplposausf on rbarbeitsplanpos.rbarbeitsplanposid = rbaplposausf.rbarbeitsplanposid
    > join rbqspruefpos on rbqspruefpos.rbaplposausfid = rbaplposausf.rbaplposausfid)
    >
    > but all rbqspruefpos.gewichtung are filled with the same value?
    > The first value found in rbarbeitsplanpos.
    Looks like you're doing it wrong.
    Subselects need to be enclosed in brackets.
    See [Subquery (subquery)|http://maxdb.sap.com/doc/7_6/60/515f3eca2a11d2a97100a0c9449261/content.htm]
    Only scalar subselects (these are the ones that by their very structure can only produce zero or one rows in the result set) can omit the brackets.
    The database cannot know that there is only one value in this column - you may try and put a aggregation function round it.
    regards,
    Lars

  • Update with a subquery

    I am trying to write a script to set all products in the Confections category that have more than 50 units in stock to a price of $10, and disable them. But I have to include a subquery to identify the category ID from the Category name Confetions. I am
    also suppose to show before and after that's why I have to select statements. I am lost, here is what I have and I don't know what I am doing wrong. I am using sql 2012. Do I need to add a inner join to convert the category name to the id?
    SELECT
    FROM
    Products
    WHERE
    UnitsInstock > 50
    AND CategoryID
    = 3
    UPDATE
    Products
    SET
    UnitPrice = 10.00
    WHERE
    Unitsinstock > 50
    AND CategoryID
    = 3
    SELECT
    FROM
    Products
    WHERE
    UnitsInstock > 50
    AND CategoryID
    = 3
    kinneylea

    Well, if you're using SQL Server 2012, I suggest MERGE command and OUTPUT clause, e.g.
    ;with cteNeedChanges as (select P.* from dbo.Products P
    inner join dbo.Categories C ON P.CategoryID = C.CategoryID
    where C.CategoryName = 'Confections' and P.UnitsInStock > 50 and P.UnitPrice <> 10)
    MERGE Products as Target USING cteNeedChanges as Source ON Target.ProductID = Source.ProductID
    WHEN Matched THEN UPDATE SET UnitPrice = 10
    OUTPUT Deleted.ProductID, Deleted.UnitPrice, Inserted.UnitPrice
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • Query tuning - update with join statement

    Hi,
    I have 2 tables (table1 and table 2) with following condition:
    TABLE 1 - Need to selection a column say staus ! = 'C'
    join emp_id and project_id of TABLE1 and TABLE2
    From join I am selecting minimun and maximum of TABLE2.salary and updating TABLE3 respective column.
    Now as per requirement I have to update required column on TABLE2.EMP_ID = TABLE3.EMP_ID
    Following is the query I have written,
    update TABLE3 T3
    set (T3.MIN_salary, T3.MAX_salary) = (
    select min(c.salary), max(c.salary)
    from TABLE2 t2, TABLE1 t1
    where t2.emp_id = t1.emp_id
    and t2.project_id = t1.project_id
    and t1.status != 'C'
    and t2.emp_id = t3.emp_id)
    The above query takes 7 min to update some 8 lakhs records. Can you please suggest some other optimized method to do so?
    Thanks in advance
    Sandeep

    Hi SBH
    Required info for "Please provide oracle version, indexes on the 3 tables and also stats info for the table from user_tables"
    1) Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit
    2) Index is not there on TABLE3 (It is temporary table)
    Composite index on TABLE 1 - column1, column2 - Index name say table1index1
    Composite index on TABLE 2 - column1, column2 - Index name say table2index1
    TABLE_NAME     NUM_ROWS     BLOCKS     DEGREE     INSTANCES     SAMPLE_SIZE     PARTITIONED
    FXO_CFW     11767341     144930     1     1     11767341     NO
    FXO_RSL_STBL               1     1          NO
    FXO_TRN     4917778     230196     1     1     4917778     NO
    execution plan is:
    Execution Plan
    Plan hash value: 3131833900
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | UPDATE STATEMENT | | 789K| 23M| 2397 (3)| 00:00:29 |
    | 1 | UPDATE | TABLE3 | | | |
    | 2 | TABLE ACCESS FULL | TABLE3 | 789K| 23M| 2397 (3)| 00:00:29 |
    | 3 | SORT AGGREGATE | | 1 | 28 | | |
    | 4 | TABLE ACCESS BY INDEX ROWID | TABLE2 | 1 | 17 | 3 (0)| 00:00:01 |
    | 5 | NESTED LOOPS | | 1 | 28 | 12 (0)| 00:00:01 |
    |* 6 | TABLE ACCESS BY INDEX ROWID| TABLE1 | 1 | 11 | 9 (0)| 00:00:01 |
    |* 7 | INDEX RANGE SCAN | IDX_TABLE1INDEX1 | 6 | | 3 (0)| 00:00:01 |
    |* 8 | INDEX RANGE SCAN | IDX_TABLE2INDEX1 | 1 | | 2 (0)| 00:00:01 |
    Thanks for quick response,
    Sandeep

  • Help with an update with join (works in access)

    This is my working query in ms access...
    UPDATE Caxnode AS A INNER JOIN Caxnode AS B ON A.node_alias = B.node_alias SET A.partition_Type = 'LDOM', A.node_mode = 'LOGICAL', A.host_id = b.host_id, A.num_of_proc = b.num_of_proc WHERE (((A.node_mode)='virtual' Or (A.node_mode)='regular') AND ((B.partition_Type)='LDOM'));
    This doesn't work in oracle, I googled and read that update doesnt work with inner join in oracle..
    can someone please help me translate this query to work on oracle?
    Thanks!
    -nikhil.

    thanks for your reply. however, im a little confused . i want to update the table caxnode for a particular node_alias if the same table has the SAME node_alias defined as partition_Type=ldom
    for eg..
    my table is as follows
    id node_alias host_id node_mode partition_type num_procs
    1 abc abc virtual null 2
    2 abc xyz logical LDOM 4
    3 def def virtual null 2
    4 def ppp logical LDOM 8
    5 abc abc regular null 3
    So those that are ldoms are marked ldom in partition_type, those that are not recognised as ldoms are marked null in partition_type. LDOM's are logical in node_mode, others are either virtual or regular in node_mode.
    Now since there are some old entries that are marked regular/virtual and NULL but are actually LDOMs, I need to go through the table and mark those as LDOM's which have same node_alias marked as LDOM later on.
    In the table above, abc is marked as LDOM in row 2, so row 1 and 5 should reflect that. the host id should change to host_id in row 2 because the same alias is defined as ldom in row 2..
    Same with def.. host_id for def should change to host_id thats in row 4 because def is also defined as ldom in row 4..
    The table should look like this
    id alias host_id node_type num_procs
    1 abc xyz LDOM 4
    2 abc xyz LDOM 4
    3 def ppp LDOM 8
    4 def ppp LDOM 8
    5 abc xyz LDOM 4

  • Update with correlated subquery

    Hi,
    I have the following SQL update statement:
    update temp_input_sms b
    set (b.provider_id,b.region_id)=
         (select provider_id,region_id
         from
         select a.PROVIDER_ID,a.REGION_ID,row_number() over (order by fraud) rn
         from icdm.smsc_lookup a
         where sysdate>=a.VALID_FROM and sysdate<a.VALID_TO
              and b.user_summarisation like a.SMSC_CODE_LIKE
         ) where rn=1)
    The problem is that there are two nested subqueries on the right side of the set clause, and in the inner subquery the 'b.user_summarisation' column is not available.
    Could anyone suggest a workaround for this problem?
    Thanks.
    Viktor

    possible workaround:
    update temp_input_sms c
    set    (c.provider_id, c.region_id) =
           (select d.provider_id, d.region_id
            from   (select a.provider_id, a.region_id, smsc_code_like,
                           row_number () over
                             (partition by a.smsc_code_like
                              order     by a.fraud) rn
                    from   smsc_lookup a, temp_input_sms b
                    where  sysdate >= a.VALID_FROM
                    and    sysdate < a.VALID_TO
                    and    b.user_summarisation like a.SMSC_CODE_LIKE) d
            where rn=1
            and   c.user_summarisation like d.smsc_code_like)
    [pre]

  • SQL Server updating with join issue

    Could someone explain to me why this update script isn't behaving the way I think it should. I'm currently running the following script:SQLUPDATE [PO_RECVR_HIST]SET [PO_RECVR_HIST].[REF] = ( CASE -- Place MUD or HOCKEY in receiver header reference fields WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'MUD' THEN 'MUD' WHEN coalesce([IM_ITEM].[ATTR_COD_1], '') = 'HOCKEY' THEN 'HOCKEY' ELSE coalesce([PO_RECVR_HIST].[REF], [PO_RECVR_HIST].[REF]) END )FROM [PO_RECVR_HIST] LEFT JOIN[PO_RECVR_HIST_LIN]ON -- Acquire all the line information for each receiver header[PO_RECVR_HIST].[RECVR_NO] = [PO_RECVR_HIST_LIN].[RECVR_NO]LEFT JOIN[IM_ITEM] ON -- Acquire all the item information (specifically attribute code 1) for each line item on the receiver[PO_RECVR_HIST_LIN].[ITEM_NO] = [IM_ITEM].[ITEM_NO]I'm trying to run this script on the PO_RECVR_HIST...
    This topic first appeared in the Spiceworks Community

    1) First Reboot your server and try again for the installation.
    2) If first fail again than Take a backup of Registry first for safe side and then delete the entries of SQL server 2012 if found take a reboot again and try to install again.
    One more thing if installation created any file then move/Delete that also before installation.

  • Update with inner-left-right joins

    On the net I find much confusing information. I am searching for examples about oracle update with joins.
    Someone knows where I can find running examples? (especially Oracle 8i 9i)
    Thanks
    Gaetano Recchi

    867873 wrote:
    On the net I find much confusing information. I am searching for examples about oracle update with joins.
    Someone knows where I can find running examples? (especially Oracle 8i 9i)
    Thanks
    Gaetano RecchiThere are lots of examples on-line if you just search for them. In particular search for a primer on ANSI SQL since "normal" SQL doen't use the inner terminology as much (though outer joins are still talked about).
    Use your favorite search engine and look for ORACLE and ANSI SQL

  • Update with Outer Join

    Is it possible to do an update that involves an outer join on the table being updated?
    Here's what I mean - currently, I have something like:
    UPDATE table_1 t1
    SET col_1 =
    SELECT t2.col_2
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    WHERE EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    UPDATE table_1 t1
    SET col_1 = 0
    WHERE NOT EXISTS
    SELECT t2.*
    FROM table_2 t2
    WHERE t2.t1_key = t1.t1_key
    Yes, I could do set all of the table_1.col_1 values = 0 first, and then do the first update, but it is inefficient given the number of records in the table that would be updated twice.
    Is there a way of combining these two updates into a single update statement?

    You could simply use your first update and omit the WHERE EXISTS clause since you want to update all the rows in table_1 anyway.
    If the subquery finds a match, it will update with the selected value. Normally, a non-match would set the column to a null but you can solve that with NVL:
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    1
                       2                    1
                       3                    1
                       4                    1
                       5                    1
                       6                    1
                       7                    1
                       8                    1
                       9                    1
    9 rows selected.
    SQL> select * from table_2;
                  T2_KEY                COL_2
                       1                    9
                       3                    9
                       5                    9
    SQL> UPDATE table_1 t1
      2  SET    col_1 = nvl (
      3                       (SELECT t2.col_2
      4                        FROM   table_2 t2
      5                        WHERE  t2.t2_key = t1.t1_key
      6                       ),0
      7                     )
      8  ;
    9 rows updated.
    SQL> select * from table_1;
                  T1_KEY                COL_1
                       1                    9
                       2                    0
                       3                    9
                       4                    0
                       5                    9
                       6                    0
                       7                    0
                       8                    0
                       9                    0
    9 rows selected.

  • Update with exists and subquery

    Hi how to pass index to this sql
    Table pap ( eqid,seq,histseq,docno,status,value1,value2)
    PK(eqid,seq,histseq) and indx (docno)
    table pa ( eqid,seq,docno,status,value1,value2)
    PK(eqid,seq) and indx (docno)
    update pa
    set (value1,value2) = (select pap.value1,pap.value2 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status = 4 )
    where pa.status=1
    and exists ( select 1 from pap
    where pap.eqid = pa.eqid
    and pap.seq = pa.seq
    and pap.histseq =1
    and pap.docno <> pa.docno
    and pap.status =4 )
    It is doing fulltable scan on pa and using hash join .
    How to write update with subquery method also ?

    There's nothing wrong with a full scan.
    Please read this explanation/example: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:9422487749968
    If you want more explanation then please follow these guidelines below, so we have sufficient inputs:
    [When your query takes too long...|http://forums.oracle.com/forums/thread.jspa?messageID=1812597#1812597]
    [How to post a SQL statement tuning request|http://forums.oracle.com/forums/thread.jspa?threadID=863295&tstart=0]
    Remember to put the tag befor and after the examples you post.
    See http://forums.oracle.com/forums/help.jspa regarding tags.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Update with Outer Join, round 2

    Thanks for those of you who helped me out on the first one (I never thought that you could use a one-row SELECT like that).
    However, here is a new version of my problem:
    I have three tables.
    Table_1 has a column that needs to be updated based on values in Table_2 and Table_3.
    Both Table_1 and Table_2 have values used to determine which Table_3 row to use.
    However, not every Table_1 row has a corresponding Table_3 row, in which case the Table_3 value to use is assumed to be 1.
    The tables and corresponding columns are:
    TABLE_1
    value_1 - the value to be updated
    key_2 - a pointer to TABLE_2
    key_3a - a pointer to TABLE_3, or a dummy value if there is no corresponding TABLE_3 record
    TABLE_2
    key_2 - the primary key
    key_3b - a secondary pointer to TABLE_3
    value_2 - a value to be used in calculating TABLE_1.value_1
    TABLE_3
    key_3a - the first part of the unique key
    ley_3b - the second part of the unique key
    value_3 - a value to be used in calculating TABLE_1.value_1
    If there is a row in table_3 that matches the table_1.key_3a and table_2.key_3b values (where table_2.key_2 = table_1.key_2):
    set table_1.value_1 = table_2.value_2 * table_3.value_3
    If there is no such row in table_3:
    set table_1.value_1 = table_2.value_2
    I want to do something like this:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_2 t2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    WHERE t2.key_2 = t1.key_2
    However, Oracle does not allow t1 to be referenced in the ON clause of the outer join.
    (Assume that every key_2 value in table_1 is in table_2 as well - it is only the key_3 value that can be a dummy.)
    If I move "t3.key_3 = t1.key_3" to the WHERE clause, then t1.value_1 is null for rows without the corresponding table_3 value.
    I can do it with a clone of table_1 using ROWIDs:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_1 t1a
    JOIN table_2 t2
    ON t2.key_2 = t1a.key_2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1a.key_3a)
    WHERE t1a.row_id = t1.row_id
    However, is there an easier way to do this using ANSI joins (i.e. without (+) syntax)?
    I have this feeling I am missing something reasonably obvious here.

    ddelgran wrote:
    Thanks for those of you who helped me out on the first one (I never thought that you could use a one-row SELECT like that).
    I want to do something like this:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_2 t2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    WHERE t2.key_2 = t1.key_2
    However, Oracle does not allow t1 to be referenced in the ON clause of the outer join.
    (Assume that every key_2 value in table_1 is in table_2 as well - it is only the key_3 value that can be a dummy.)
    If I move "t3.key_3 = t1.key_3" to the WHERE clause, then t1.value_1 is null for rows without the corresponding table_3 value.
    I can do it with a clone of table_1 using ROWIDs:
    UPDATE table_1 t1
    SET value_1 =
    SELECT t2.value_2 * NVL(t3.value_3, 1)
    FROM table_1 t1a
    JOIN table_2 t2
    ON t2.key_2 = t1a.key_2
    LEFT JOIN table_3 t3
    ON (t3.key_3b = t2.key_3b and t3.key_3a = t1a.key_3a)
    WHERE t1a.row_id = t1.row_id
    However, is there an easier way to do this using ANSI joins (i.e. without (+) syntax)?
    I have this feeling I am missing something reasonably obvious here.You might want to refer to my post in your original thread how to use join views in updates. You can use ANSI join syntax there, too:
    Re: Update with Outer Join
    You would end up with something like this (note: untested):
    UPDATE
      SELECT t1.value_1, t2.value_2 * NVL(t3.value_3, 1) as new_val
      FROM table_1 t1
      INNER JOIN table_2 t2 ON (t2.key_2 = t1.key_2)
      LEFT JOIN table_3 t3
      ON (t3.key_3b = t2.key_3b and t3.key_3a = t1.key_3a)
    SET value_1 = new_val;And again the same restrictions regarding key-preserved tables apply as described in the post referred to.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Update openquery remote table with join

    Hi All,
    I have a problem with OPENQUERY update on remote table. I've googled for days, and can't solve the problem.
    Here is the problem:
    Local server MS SQL 2005.
    Remote server: MySQL.
    The linked server is communicating through MySQL ODBC 5.1
    I created the following code for update (tried many other version too, this is the last one):
    update openquery(Remoteserver,'select products_id, products_price, products_last_modified, products_stock from products1')
    set
    products_price=A.products_price,
    products_stock=A.products_stock,
    products_last_modified=getdate()
    FROM
    (select * from vi_products_update) AS A INNER JOIN
    openquery(octopus, 'select products_id from products1')AS B
    ON A.products_id=B.products_id
    When I run the query the columns are updated with the same value, for each record. It looks the value is the first which match the criteria. Each (remote and local) table has as primary key products_id. In this example I used as result set for local a view, but I have the same result if I use a table.
    the products_last_modified column is updated in order, and if I update for e.g. the products_price with a constant that is ok too. The problem should be somewhere with join, but I can' get it where.
    THX for any help
    ab

    Hi
    Did you ever solve this problem
    I have the same issue trying to update many rown in a MySQL table from SQL2005 using the syntax below,
    UPDATE
    openquery(DEV,'select id, `desc` from todLocationGroups')
    SET [desc] = V.Destination_Group FROM
    (select * from VTM_TOD_Rate) as V inner join
    openquery(DEV,'select id, `desc` from todLocationGroups') as K
    ON K.id = V.TOD_LG_ID
    but i get this error
    OLE DB provider "MSDASQL" for linked server "KAYOTE_DEV" returned message "Row cannot be located for updating. Some values may have been changed since it was last read.".
    Msg 7343, Level 16, State 4, Line 1
    The OLE DB provider "MSDASQL" for linked server "KAYOTE_DEV" could not UPDATE table "[MSDASQL]". The rowset was using optimistic concurrency and the value of a column has been changed after the containing row was last fetched or resynchronized.

  • Update statement with joining other tables

    Hi ,
    I have two table one is containing xml file , basically i need to read from those xml file then update to another table based on some condition.
    UPDATE TRCB_XBRL_STG_2 STG
    SET PROFIT =
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//PROFIT ', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//PROFIT ', 'xmlns:acra=".."')
      ELSE STG.PROFIT
      END,
      SET REVENUE=
      case when xbrl.isconsolidatedacc='Y' and EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..."') is not null
      THEN EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE.', 'xmlns:acra="..."')
      WHEN XBRL.ISCONSOLIDATEDACC='N' AND EXTRACTVALUE(XBRL.XBRLFILE,'//REVENUE', 'xmlns:acra="..') IS NOT NULL
      THEN extractValue(XBRL.xbrlfile,'//REVENUE', 'xmlns:acra="REVENUE"')
      ELSE STG.REVENUE
      END,
      ... (around 100 columns)
    FROM  TRCB_XBRL xbrl ,TRCB_XBRL_STG_2 STG
    WHERE STG.XBRL_ID = XBRL.XBRL_ID Number of columns are around 100 , please anyone suggest how to use update statement with joining two tables.

    Hi,
    If all the values needed to update a given row of table_x are coming from the same row of table_y (or from the same row of a result set of a query involving any number of tables), then you can do something like this:
    UPDATE  table_x  x
    SET     (col1, col2, col3, ...)
    =     (
             SELECT  NVL (y.col1, x.col1)
             ,         NVL (y.col2, x.col2)
             ,         NVL (y.col3, x.col3)
             FROM    table_y  y
             WHERE   x.pkey   = y.expr
             AND         ...
    WHERE   ...
    ;If the WHERE clause depends on the same row of table_y, then it will probably be simpler and more efficient to use MERGE instead of UPDATE.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

Maybe you are looking for

  • I want to upgrade my Imac from tiger 10.4.11 to Mac OS 10.6 Snow Leopard. What is the best way to do this.

    I have just purchased an iphone 4 and it needs me to have the latest itunes on my computer.  I have not upgraded by computer for some time and thought this is probably the time to do it. My computer is an imac intel with Tiger 10.4.11. I want to upgr

  • How do I CREATE IF NOT EXISTS Temp table in PLSQL?

    hello, how do I CREATE IF NOT EXISTS Temp table in PLSQL? The following table is to be created in FIRST call inside a recursive function (which you'll see in QUESTION 2). QUESTION 1: CREATE GLOBAL TEMPORARY TABLE TmpHierarchyMap                      

  • Restricting access to the Admin WebConsole of WebAccess 2012

    Hi, With the new WebAccess 2012 web application, the console is now a WebConsole that can be accessed by the URL http://<server>/gw/webacc?action=Admin.Open I search the KB, the documentation and now this forum, looking for a way to restrict access t

  • Keep packages up to date

    Hi! I'd like to know who to keep certain packages up to date. I have mirrored the whole current dir with rsync but i just need a few packages from extra. Now i run rsync for extra with --delete and --existing which deletes the packages if they are ol

  • Using cfexecute to start FMLEcmd.exe

    Hi! I'm trying to use <cfexecute> to start the command line utility to start a fmle session. Coldfusion is running locally of course not on a remote server :-) I am trying to use Coldfusion to make a sort of an easy start stop interface for the FMLE.