How to combine update stmts with different filters and multi-columns?

Hi,
I found these following update stmts in one of our long running jobs. I'd like to see if it is possible to combine it in one update or merge stmt so I can reduce the scan time on the same table from 4 times to 1 time. But I'd need some expert suggestions for how to do that. Here are the stmts:
UPDATE table1 c
SET (polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,valid)=(SELECT DISTINCT polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,'A'
FROM table2 v
WHERE v.polnum=c.pol# AND
v.polren=c.ren# AND
v.polseq=c.seq# AND
v.vehnum=c.veh#)
WHERE c.polnum IS NULL;
UPDATE table1 c
SET (polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,valid)=(SELECT DISTINCT polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,'B'
FROM table2 v
WHERE v.polnum=c.pol# AND
v.polren=c.ren# AND
v.polseq=c.seq# AND
v.mainveh='Y')
WHERE c.polnum IS NULL;
UPDATE table1 c
SET (polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,valid)=(SELECT DISTINCT polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,'C'
FROM table2 v
WHERE v.polnum=c.pol# AND
v.polren=c.ren# AND
v.polseq=0 AND
v.mainveh='Y')
WHERE c.polnum IS NULL;
UPDATE table1 c
SET (polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,valid)=(SELECT DISTINCT polnum,polren,polseq,vehnum,
compgrp,prodgrp,uwsys,comp,
state,prod,rrdate,brand,
agycode,AGYCLASS,'D'
FROM table2 v
WHERE v.polnum=c.pol# AND
v.polren=0 AND
v.polseq=0 AND
v.mainveh='Y')
WHERE c.polnum IS NULL;
Table1 has 800000 rows, Table2 has 200 million rows. In table1, about 12.5% rows has a null polnum, so 12.5% data will be updated.
Thank you in advance with all your suggestions!

the reason I never specified the joins is because I thought the joins were there to derive the Valid indicator, in which case they are not required if you are using the CASE statement. The join, "V.Polnum = C.Pol#" is still required as this is across all rows! If that is the case, then it can be simplified even more so;
update   Table1 C
set      (Polnum,Polren,Polseq,Vehnum,Compgrp,Prodgrp,Uwsys,Comp,State,Prod,Rrdate,Brand,Agycode,Agyclass,Valid) =
            ( select   distinct Polnum
                               ,Polren
                               ,Polseq
                               ,Vehnum
                               ,Compgrp
                               ,Prodgrp
                               ,Uwsys
                               ,Comp
                               ,State
                               ,Prod
                               ,Rrdate
                               ,Brand
                               ,Agycode
                               ,Agyclass
                               ,case
                                  when (Polren + Polseq=0) and (Mainveh='Y') then
                                        'D'
                                  when (Polren=0) and (Polseq>0) and (Mainveh='Y') then
                                        'C'
                                  when (Polren>0) and (Polseq>0) and (Mainveh='Y') then
                                        'B'
                                  when (Polren>0) and (Polseq>0) and (Mainveh!='Y') then
                                        'A'
                                end as Valid
             from      Table2 V
             where     V.Polnum = C.Pol#
where    C.Polnum is null;However if you are returning more rows than what you are expecting from the above update statement because the joins are being used to limit the data as well, then this might be more appropriate:
update   Table1 C
set      (Polnum,Polren,Polseq,Vehnum,Compgrp,Prodgrp,Uwsys,Comp,State,Prod,Rrdate,Brand,Agycode,Agyclass,Valid) =
         ( select v2.PolNum
               ,v2.Polren
               ,v2.Polseq
               ,v2.Vehnum
               ,v2.Compgrp
               ,v2.Prodgrp
               ,v2.Uwsys
               ,v2.Comp
               ,v2.State
               ,v2.Prod
               ,v2.Rrdate
               ,v2.Brand
               ,v2.Agycode
               ,v2.Agyclass
               ,case
                  when (v2.Polren + v2.Polseq=0) and (v2.Mainveh='Y') then
                        'D'
                  when (v2.Polren=0) and (v2.Polseq>0) and (v2.Mainveh='Y') then
                        'C'
                  when (v2.Polren>0) and (v2.Polseq>0) and (v2.Mainveh='Y') then
                        'B'
                  when (v2.Polren>0) and (v2.Polseq>0) and (v2.Mainveh!='Y') then
                        'A'
                end as Valid_Flag
            ( select   distinct Polnum
                               ,Polren
                               ,Polseq
                               ,Vehnum
                               ,Compgrp
                               ,Prodgrp
                               ,Uwsys
                               ,Comp
                               ,State
                               ,Prod
                               ,Rrdate
                               ,Brand
                               ,Agycode
                               ,Agyclass
                               ,Mainveh
             from      Table2 V
             where     V.Polnum = C.Pol#
             ) v2
         where (v2.Polren = C.Pol# or v2.Polren = 0)
         and   (v2.Polseq = C.Seq# or v2.Polseq = 0)
where    C.Polnum is null;As before, both remain UNTESTED!

Similar Messages

  • Combine update stmts with different columns and criteria

    Hi All,
    I have the following 3 update stmts that update the same table. The table DSVEHS has 45 million rows. The table PPDSDETL has 95 million rows. How to combine them? I'd like to reduce the times to scan those tables. There is a primary key on PPDSDETL for dipoln, direnn, diseqn, didscd and another column not in the query.
    Please give me some suggestions. Thank you in advance.
    UPDATE DSVEHS
    SET accfgn_sur = 'Y'
    WHERE EXISTS (SELECT 'X' FROM PPDSDETL
    WHERE polnum = dipoln
    AND polren = direnn
    AND polseq = diseqn
    AND UPPER (TRIM (didscd)) = 'ACCFGN');
    update DSVEHS
    set mviofg_sur = 'Y'
    where exists (select 'X' from PPDSDETL
    where POLNUM=DIPOLN
    and POLREN =DIRENN
    and POLSEQ =DISEQN
    and upper(trim(DIDSCD)) ='MVIOFG' ) ;
    update DSVEHS
    set accfre_dsc= 'Y'
    where exists (select 'X' from PPDSDETL
    where POLNUM=DIPOLN
    and POLREN =DIRENN
    and POLSEQ =DISEQN
    and upper(trim(DIDSCD)) ='ACCFRE' ) ;

    Hi,
    user13081819 wrote:
    Hi Frank:
    Here is a set of sample result:
    POLNUM POLREN POLSEQ VEHNUM DRVNUM TRANSD MULTIC PRODUC HOMEOW NONOWN RENEWA DRIVER OT ACCFGN_SUR MVIOFG_SUR ACCFRE_DSC
    1111111 0 1 2 0 mmmmmm xxxxxx Y N Y
    2222222 0 3 1 0 Y N Y
    ...This site normally won't print multiple spaces in a row.
    Whenever you post formatted text, like your results, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    The table structures are:
    DSVEHS
    Name Null? Type
    POLNUM NOT NULL NUMBER(9)
    POLREN NOT NULL NUMBER(2)
    POLSEQ NOT NULL NUMBER(2)
    ...Post CREATE TABLE statements instead.
    Please let me know if you need more information.Besides the things mentioned above, post INSERT statements for the sample data that produces the given results.
    Did you say which version of Oracle you're using?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to create 2D array with 3 rows and unlimit column?

    how to create 2D array with 3 rows and unlimit column?

    Here are images of what I described in my previous post
    Message Edited by JoeLabView on 11-14-2007 07:56 AM
    Attachments:
    2D-array_code.PNG ‏7 KB
    2D-array_values.PNG ‏13 KB

  • How to combine two applications with different workspaces in APEX

    Hi,
    Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    Thanks in advance,

    Hello Satya,
    >> I am Satya …
    Please take one more step to help us and update your forum handle to something friendlier than user123… Thanks.
    >> Can anyone help out in merging two applications with different workspaces in APEX 3.2 ?
    This is not a trivial task.
    You didn’t mentioned if both workspaces sharing the same APEX instance, or they are on two different instances (machines). I believe the latter is a pre-condition to a success.
    First you need to remember that importing an APEX component, like a single page, is possible only to the same application that it was exported from. This is still valid if you have the same workspace on two separate APEX instances – one is an import of the other (which makes it an identical copy). Still, the application ID must be the same, or you’ll get the following error: “This page was exported from a different application or from an application in different workspace. Page cannot be installed in this application.”
    You can’t simply manipulating the export file, if the two workspaces are sharing the same APEX instance, as all workspaces on the same instance shares the same APEX metadata files, and you’ll receive a “unique constraint violated” error messages. That means you can’t import one application into the workspace of the other, even if you are using a different application ID.
    As far as I can see, the only viable way of doing an application merge is to have two identical workspaces, on two separate APEX instances. The two applications should share the same application ID, although this parameter can be changed in the import file. You should export the page in one application – on the first instance – and import it into the other application – on the second instance.
    You should also make sure that the exported page ID doesn’t exist on the target application, otherwise it will be replaced by the new imported page. Also, if the imported page include references to shared components that are not defined on the second application, it might also pose a problem.
    As I said, this is not trivial. The benefits are mostly depend on the amount and complexity of the pages you want to merge. If they are not many, and simple, you should consider just re-creating them on the target application. If they are very complex, the merge might fail anyway.
    Regards,
    Arie.
    Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.

  • How to combine a bar with a line in a chart

    Post Author: rbcdexia
    CA Forum: Charts and Graphs
    We want to combine data in bars and with a line showing in one chart.
    Is that possible? How do you configure your chart?
    The line and the bars are based on the values from different fields in the same table.

    Post Author: pareshb
    CA Forum: Charts and Graphs
    We are using Crystal Reports for Visual Studio 2005. Can you please let me know how to combine a bar with a line chart.
    Thanks in advance.Paresh

  • How can i share documents with different users on the same mac?

    How can i share documents with different users on the same mac?

    Shared how? The other users can read the documents or you all can read and write the documents?
    The first is easy just place the documents in /Users/Shared anyone can access the files there and the other users will be able to read them.
    The second is a bit trickier.

  • Cant update apps. asks for password for another account i had on a dell notebook. either i forgot the pass word or its not taking it. i can download apps,music with present mac note book but not apps. how can i update apps on my mac and iphone 4?

    cant update apps on my mac or iphone4. asks for password for another account i had on a dell notebook. either i forgot the pass word or its not taking it  . i can download apps and music.  how can i update apps on my mac and iphone 4?

    I had the same problem today and was able to resolve it without having to do a restore or reset. The problem had something to do with my mail accounts. The upgrade reset my mail settings, switching both my gmail and my .mac mail to "archive all mail". I went into the General Settings, disabled that setting, and resynced the phone. The "other" storage allottment dropped back down to less than a gig.
    Before you restore or reset, I would try that first.

  • HT4759 how do you update icloud with contacts transferred to Iphone by verizon

    How do you update icloud with contacts transferred to Iphone by Verizon?  The only contacts that show up in icloud are the ones I entered myself to the phone.

    You'll need to copy them to iCloud in order to see them on your PC.  To do this, do the following:
    Go to Settings>iCloud, turn Contacts to Off, choose Delete from My iPhone when prompted (they will still be in iCloud).
    Download the app My Contacts Backup.  Use this to backup the remaining contacts on your phone (from Verizon) as a vCard attachment to an email that you send to yourself.  Confirm that you have received the email.
    Go to Settings>iCloud and turn Contacts back to On.
    Open the My Contacts Backup email and tap the attachment to import the Verizon contacts back to your phone.  They should now be in iCloud, and appear on your PC.  You may see duplicate contacts on your phone because you are still viewing both the contacts from Verizon as well as the copies now in iCloud.
    Open Contacts on your phone and tap Groups, tap the Groups that were imported from Verizon so they are unchecked and tap Done.  This will hide them from view and illiminate the duplicates.

  • Cannot insert more than 1 WSUS update source with different unique ids

    Hello LnG
    I am aware that are a whole bunch of forum threads on this error however little bit of additional help would be of great help, as I have nearly tracked this 'pain' down.
    Our environment: SCCM 2007 R3
    1 Central
    15 Primaries and a whole bunch of secondaries
    Single WSUS server
    OK, so we have just taken handover of this new account and still getting a hang of the creek and corners in the environment. We have about 1000 machines sitting in "Failed to download updates" state.  Error
    = 0x80040694
    WUAHandler.log:
    Its a WSUS Update Source type ({A2762CA9-9739-4260-9C3A-DC4B36122E16}), adding it
    Cannot insert more than 1 WSUS update source with different unique ids
    Failed to Add Update Source for WUAgent of type (2) and id ({A2762CA9-9739-4260-9C3A-DC4B36122E16}). Error = 0x80040694.
    Its a WSUS Update Source type ({BCB9D60B-2668-459B-BFFD-6DDD11AADC53}), adding it
    Existing WUA Managed server was already set (http://WSUSServername:8530), skipping Group Policy registration.
    Added Update Source ({BCB9D60B-2668-459B-BFFD-6DDD11AADC53}) of content type: 2
    WUAHandler
    Async searching of updates using WUAgent started.
    Checked the
    CI_UpdateSources table and found 2 Update sources  unique ids:
    {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} Date Created 2011-01-11 03:47:52.000/Date Modified 2011-01-11 03:47:52.000
    and
    {A2762CA9-9739-4260-9C3A-DC4B36122E16} Date Created 2014-07-09 02:48:46.000 / Date Modified 2014-07-09 02:48:46.000
    My questions:
    Can I rely on the last modified/created date for inactive update source and delete it off the database? in this case can I delete {BCB9D60B-2668-459B-BFFD-6DDD11AADC53}?
    When i browsed to the registry location on the Central Server
    HKLM\Software\Wow6432Node\Microsoft\SMS\Components\SMS_WSUS_SYNC_MANAGER i saw the update source as {BCB9D60B-2668-459B-BFFD-6DDD11AADC53}.
    Does it imply that a stale record?
    Any help/guidance will be much appreciated :)

    Well!! My wsyncmgr.log  says  this: 
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX to 18
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX1 to 18
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX2 to 18
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX3 to 18
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX4 to 18
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX5to 1
    Set content version of update source {BCB9D60B-2668-459B-BFFD-6DDD11AADC53} for site XX6 to 18
    So, this is an active update source! ?? I cannnot uninstall and reinstall SUP currently. Any thoughts?? Any ody?

  • How do I write harmonies with different note values?

    I'm new to GarageBand and have been working with the score on the software grand piano.  At first, I'll write a melody line and then go back to add harmony.  When I try to add a harmony that has a different rhythm, GarageBand automatically changes the melody to match the rhythm of the harmony.  I'm trying to write the parts in the same staff so that the piano part can all be printed on the same page.  Any thoughts/help on how to write the piece with different rhythms in one measure?

    Have you tried to click the clef to get two lines of notation? I enter the chords in the bass clef line, if I need a different rhythm, for example: Or make the edits in piano roll.

  • How to improve image resolution with using filters

    how to improve image resolution with using filters?

    image resolution, Please check the below links. They should give you a clear idea about Resizing and resampling images.
    http://helpx.adobe.com/photoshop/kb/advanced-cropping-resizing-resampling-photoshop.html#m ain_Resizing_and_resampling_images
    Understanding Resize vs. Resample | Learn Photoshop CS6 | Adobe TV
    Cheers!
    ~ Arpit

  • How can I update Jdev with new JDK

    I currently have JDev323 and I wonder how can I update it with new JDK 1.4.

    What you should do is update the JDeveloper version that you use - 3.2 is sooooo old.
    Get Oracle JDeveloper 9.0.4 and you'll have JDK 1.4 built in.
    I don't remember if that feature was in 3.2 but since JDeveloper 9 you can switch the JDK - it is in the online help - do a search for the word JDK.

  • HT204266 How do I update apps with the new version of itunes

    How do you update apps with the new version of Itunes ?

    If you're at the iTunes store, click on Library button at the top right. Then on the top-left side click on Apps and at the bottom right click on Check for updates.

  • How to Link two Facts with Different Time Granularity (Year, Quarter) to a Single Time Dimension

    Hello All,
    I have the below scenario where i have Two Facts Fact Quarterly and Fact Yearly but one Time Dimension which has Quarter grain.
    So my question is how do i Establish relationship from Fact Yearly to Time Dimension??
    Ex: 

    Hi naveej,
    According to your description, you want to know how to build the relationship with time dimension and fact tables. Right?
    Based on your screenshot, it's better to have only one fact table for sales and build the relationship with time dimension. To determine quarterly or yearly data only depends on how you slice the time dimension. However, I notice that the Revenue for year
    is different from the aggregated Profit for quarters. If the Revenue and Profit are different measure, you need to have two fact tables. And you should build the relationship (Regular) between TimeDim and FactYearly on YYYY attribute.
    Reference:
    Defining a Fact Relationship
    Best Regards,
    Simon Hou
    TechNet Community Support

  • HT4623 How do you update 3GS with iOS 4.3?

    How do you update 3GS with iOS 4.3?

    You can update it to 6.0.1 if you have a 3gs by following the directions in the article you linked, under updating from itunes on your computer.
    iOS: How to update your iPhone, iPad, or iPod touch
    If it is a 3g, then it can only to 4.2.1

Maybe you are looking for