Basic Update Question

Dear Group,
I have two tables in two different R2 databases. We will call them Table1 and Table2 for convenience. I would like to update records in Table2 from the values of rows in Table1.
 I would like to loop through Table1 and find the corresponding record in Table2 and update the fields Table2.PriceChangeDate (datetime) – ‘2014-04-01 00:00:00.000’ and Table2.PriceChange (float) with the value of the Table1.Price (float).
So to me it would be:
Update Table2.PriceChangeDate = ‘2014-04-01 00:00:00.000’ AND Table2.PriceChange
 = Table1.Price
WHERE
Table2.ProductID  = Table1.ProductID
 AND Table2.PriceLevelID = Table1.PriceLevelID  AND Table2.TimeBand
 = Table2.TimeBand
The table structure is:
[Database1].[Table1]:
ID (nvarchar(15)) - Identity
ProductID (nvarchar(15))
PriceLevelID (nvarchar(15))
TimeBand (nvarchar(15))
Price (float)
[Database2].[Table2]:
ID (nvarchar(15)) - Identity
ProductID (nvarchar(15))
PriceLevelID (nvarchar(15))
TimeBand (nvarchar(15))
PriceChangeDate (datetime)
PriceChange (float)
Thanks very much for your help. It will be easy for the group I am sure but it has me slightly confused.
Alastair (from UK)

The one advantage with using MERGE over UPDATE is that the join conditions you causes ambiguity, this will result in error, whereas with UPDATE you will get an indeterministic result.
The potential ambiguity here is that if one row in the target table matches several rows in the source, this raises the question which price you want to copy. This will not happen if you join on a complete key in the source table, so it may not be a concern
at all.
The other advantage with MERGE over this specific form of UPDATE is that MERGE is ANSI-compliant syntax, whereas this form of UPDATE is not. There is another form of UPDATE which is both ANSI-compliant, and which also will raise an error in case of ambiguities:
Update DB1.dbo.Table1
SET  PriceChangeDate = '2014-04-01T00:00:00.000'
    ,PriceChange     =
       (SELECT t1.Price
        FROM   DB2.dbo.Table2 AS t2
        WHERE  DB1.dbo.Table1.ProductID = t2.ProductID
          AND  DB1.dbo.Table1.PriceLevelID = t2.PriceLevelID
          AND  DB1.dbo.Table1.TimeBand  = t2.TimeBand)
WHERE EXISTS (SELECT *
        FROM   DB2.dbo.Table2 AS t2
        WHERE  DB1.dbo.Table1.ProductID = t2.ProductID
          AND  DB1.dbo.Table1.PriceLevelID = t2.PriceLevelID
          AND  DB1.dbo.Table1.TimeBand  = t2.TimeBand)
But as you see, this model is even more cumbersome than the MERGE statement, and many unexperienced programmers lose themselves in this syntax.
In practice, most people in the SQL Server world use the syntax that Dan used, and as long as you aware of the risks it incurs, there is no problem with it.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • Basic iPhoto questions:

    I have some Basic iPhoto questions before I start using the program:
    - does iPhoto apply any compression or change images in any way when they
    are imported?
    - after images are imported, can the original source folder of images be deleted off of the mac?
    - can Quicktime files exported from iPhoto be viewed on a Windows computer?
    - can iPhoto handle large resolution images that might be as large as 8-15mb each? does it display them quick? are there any known file size issues?
    Thanks!!!!

    kat.
    Is there a way to use iPhoto on a network so other users can read and possibly write to an iPhoto library on a networked mac?
    iPhoto is a consumer level photo organiser, not a server. It's possible to share photos but libraries are very difficult and fraught with the danger of database corruption. Some have reported success.
    Is it possible to password protect or secure certain images in the library so they can not be seen by anyone?
    No. The best I can suggest there is to create a second library and store it in a secure area like a protected dmg. But remember, you can only have one library open at a time.
    After photos are deleted from iPhoto, are there any remaining traces or cached files anywhere other than the trash
    If you delete photos from iPhoto and empty the iPhoto trash then the pics are removed from the Finder as well. They remain as findable as any other deleted file from that point, which is, very, if the searcher in knowledgeable.
    Regards
    TD

  • Object class deployment - Basic form question

    OK, I subclass calendar object from Oracle provided standard
    object class. What do I need to deploy to use this form now
    apart from calendar.pll and my fmx. What about the object class
    from which I sub-class. Do I need to compile and deploy that
    also? How will form resolve this on run time the parent object
    class as I really did not copy, just sub class and we do not
    deploy original class? Basic form question. Thanks.

    You can set the "help" property on the field (which gives you the little "information" icon link beside the field).
    You could also try adding another field of another class above or below:
    <Display class='InlineAlert'/>
    <Display class='ErrorMessage'/>
    <Display class='HtmlPage'/>
    ..etc
    -Rob

  • Can we make things more Useful...? not an update question.

    Ok well i said its not an update question.. well it kinda is.
    today is friday.. the release date of the new iphone 3g.. great.. i love my iphone.. im goin to wait a week or so before i go ahead and buy the new phone for sake of bugs and lil tweaks..
    ok so today i dont know what drove me to update my iphone.. and it got totally bricked for 3 hours.. until i finnally got thru using the "clicking" solution... well i understand the server is overwelmed.. and everyone is updatin and the same time.. but there was a prompt askin if i wanted to update and get the latest iphone software and the latest version of itunes... good.. lets all download it.. most of us it will take 3-6 hours for the iphone to update because the whole problem with the overload on apples side...
    ..BUT...
    what if we cant wait that long?
    i SYNC'd my iphone before the update.. well everyone does... itunes prompts you to do so.. WHY.. emphasizing on WHY... if we synced the phone to our computer systems.. and a problem like for example is goin forth now with this update... CAN'T we just restore our iphones back to how it was before we even tried updating it?
    IT did SAVE to our computers right?
    why cant we just double click here, right click right there..
    and BOOM..
    back for pre 2.0 days.. well until after the storm has passedt..
    why cant we have that option in itunes... heck why not?
    hey doctors will always have beepers to get in contact with.. so hey the whole life death situation thing means it isnt that that THAT bad.. but hey everyone needs there cell phone and people use cell phones.. this one in particular for business.. so maybe we could have avoided some confrontation to some conference calls and clients.. etc... well regardless.. as easy for the update to have made the iphone in a way "bricked".. i think it should have been easy to restore to pre 2.0 .
    windows has that option in its system restore feature...
    download something that messes up your system? virus? update that doesnt work well with the OS?.. restore to an earlier date is an option in the control panel..
    i think itunes need something like that with the iphone version..
    last but not least..
    i love my iphone :-D

    uppers

  • Updated question: Both Mac & PC links possible??

    I apologize right away for posting a new topic with my updated question. But I realized I didn't phrase it right to get any help.
    The question is - is it possible make both Mac links and PC links available on one disk. They would be in separate chapters. (i.e., directing Mac users to this page and Pc to another) Anyone tried this.
    thanks.

    hi jujubes
    I just realised I misled you in my replay to your earlier post due to my poor writing skills
    to clarify:
    I suggest using Intellidisc to create the links for playback on a PC
    you would also use DVD@Access within DVDSP to create the links for Mac playback
    the links will work when played back on both mac and PC from this single disc
    the Intellidisc website gives all this in a tutorial at:
    wwwintellidisc.com

  • Adding Date/Time Field + X Number of Days - Basic Calculation Question

    I am assuming this is a basic calculation question. New to Adobe LiveCycle Forms.
    I have a simple form containing a table. The table appears as such:
    Text
    Formatted as Date/Time Fields
    Header 3
    Monday
    user wil choose the beginning date (Date/Time) this is DateTimeField1
    Tuesday
    this should calculate DateTimeField1 + 1
    Wednesday
    this should calculate DateTimeField1 + 2
    Thursday
    this should calculate DateTimeField1 + 3
    Friday
    this should calculate DateTimeField1 + 4
    Saturday
    this should calculate DateTimeField1 + 5
    Sunday
    this should calculate DateTimeField1 + 6
    Calculations are performed after the date is chosen for Monday. My mind tells me the simple calculation of DateTimeField1 + 1 is not going to work (and in fact doesn't!) as it needs to change Monday to a number first. I saw on another thread the following:
    Num2Date(Date2Num(Date(DateTimeField1), "DD.MM.YYYY")+7, "DD.MM.YYYY")
    Thought this was going to get me close. No cigars though!
    Any quick help is greatly appreciated. And since I am new to this, details about what needs to be changed would be great too!
    Thanks

    Here an addition for you date field.
    This FormCalc script in the exit:Event will check it the selected date is on a monday.
    If not it will go the days back until the last monday.
    var Selection = Date2Num($.formattedValue, DateFmt(2))
    var WeekDay = Num2Date(Selection, "E")
    var NewDate
    if (WeekDay eq 1) then
              NewDate = Selection - 6
    elseif (WeekDay eq 3) then
              NewDate = Selection - 1
    elseif (WeekDay eq 4) then
              NewDate = Selection - 2
    elseif (WeekDay eq 5) then
              NewDate = Selection - 3
    elseif (WeekDay eq 6) then
              NewDate = Selection - 4
    elseif (WeekDay eq 7) then
              NewDate = Selection - 5
    else
              NewDate = Selection
    endif
    $ = Num2Date(NewDate, "EEE DD.MM.YYYY")
    Hope this helps, too.

  • Software Update Questions

    Hi everybody,
    I'm still relatively green in the computer world, so, I'm sure these questions are way to "rookie" for you. Nevertheless; here they are.
    Software Update Questions:
    1. What is J2SE 5.0 Release 4, version 4.0 (39.3 MB) and, is it necessary to install?
    2. What is X11 Update 2006, version 1.1.2 (51.0 MB) and, is it necessary to install?
    In case you need to know, I have Mac OS X (10.4.8) with a Verizon FIOS connection.
    Thanks,
    Wayhun
    iMac   Mac OS X (10.4.8)  

    J2SE 5.0 is the latest version of Java. Mac OS X originally ships with Java 1.4 and this gives you the opportunity to upgrade to the latest version.
    It's an optional upgrade since there are many changes between Java 1.4 and java 5, so some people might prefer to hold off until they've verified their Java apps work with the new version. For most people, though, it isn't an issue.
    X11 (also known as XWindows) is a standard GUI interface for Unix systems. If you're using X11 you'd probably alredy know about it and therefore wouldn't be asking this question. It's not going to cause any problems if you update it, but it won't offer any advantage unless you're running X11-based applications.

  • Basic Exporting Question

    My main question is a very basic exporting question, but here is a super-condensed explanation of my big-picture goal for context:
    Large (~450 MB) aiff on CD --> trim w/ Quicktime --> small (~16 MB) MP3 in iTunes
    I would like to take an audio file (aiff) that is approximately 450 MB and export it from Quicktime and in doing so, reduce the file size and convert it to MP3. When I simply try to export it, it doesn't ask me about what size I want, nor does it give the option of MP3 formatting.
    I have figured out how to reach my goal, but it's a mess. After I make my trims in QT, I have to:
    1. select "share" instead of "export".
    2. It asks me what size I want and I select small.
    3. The file is then exported as a Quicktime movie into Mail and the size is reduced from 450 MB to about 20 MB.
    4. I then have to "right-click" on the attachment in the email that is created,
    5. save the attachment,
    6. discard the email,
    7. import the file into iTunes, and
    8. create an MP3 in iTunes to finally arrive at my goal.
    This seems like a ridiculously convoluted process to change a large aiff to a small MP3 and put it in iTunes. Any suggestions?

    Thanks. I guess the basic answer to my question is that it can't be done in one or two fell swoops. The problem is that it starts on a burned disc, and I need to make edits to it before it ends up in iTunes (to be eventually used in iWeb). I was hoping to avoid juggling back and forth between iTunes and QT. I either would have to send it back to QT to do the edits after -->iTunes-->mp3, or import the large file from the CD to QT, make the edits, save changes, import large file to iTunes, convert to mp3.

  • Basic database question, and subscribe/unsubscribe code

    Hi there
    Although I've created and manage a website, and about a million years ago I worked with databases, I'm still a bit green and in need of some help ...
    I have the website based on my local machine (laptop).  I want to use a subscribe/unsubscribe for a newsletter via the website.
    Before I go ahead with this, I need to clarify a very basic database issue ... would I have to always leave my laptop running in order for people to be able to subscribe to the newsletter on the website, i.e. will it still connect to the database if the laptop is not running?
    I'm using Dreamweaver 3, so I hope I can use this version to connect with a database?  I did install Dreamweaver 4 on one occasion with the intent of upgrading the website to it, but because I'm still a bit unsure of myself and was unfamiliar with the changes the newer version created, I decided to leave it on Dreamweaver 3 rather than risk stuffing the website up completely!
    I also have Dreamweaver UltraDev but for some reason it won't install.
    I'm hoping to follow instructions given on Dreamweaver Developer Centre for setting up a PHP development environment (http://www.adobe.com/devnet/dreamweaver/articles/setting_up_php.html).
    If anyone would be so kind as to advise whether I'm on the right track with all this, using Dreamweaver 3, that'd be great!
    Also, I'm sure this is unlikely, but is there any way to include a subscribe-unsubscribe without having to actually use a database?
    Many thanks in advance    :-)
    Cheers, Chrissie

    Thanks for your help and advice - much appreciated.  I'm going to go the way
    of hosting, as you suggest, and save myself the heartache  
    Quoting jj12689 <[email protected]>:
    To answer your first question, yes your laptop needs to be powered on
    for users to be able to access the database and subscribe/unsubscribe.
    There is another way of doing it, but it requires more work on your
    part. You could make an online program that would generate SQL
    statements and place them in a text document on the server. Every time a
    user subscribes/unsubscribes it would add them to the end of the text
    document. Then you could make an update button on a back-end admin page
    that you would have to push that would take that text file, open it and
    take the sql statements and submit it to the database on your computer.
    I would advise against this method, since it is time consuming, and not
    very fast for today's world. I would recomend using a server based
    database, if the host you currently have dose not have a database, I
    would recomend finding another host. I use surpasshosting.com for my
    hosting because they are cheap, reliable, and have all the requirements
    I need.
     
    Hope this helps...
    >

  • Basic Delta question

    Hello, I have a basic question about dso update. so if i get a record like this in my dso from ecc:
    Name Amount
    John $100
    This record will go into new table first then in active and change log will also be updated right?
    In the next load someone modified the amount and reduce it from 100 to 80 and i will get something like this
    Name Amount
    John -$100
    John $80
    Change log will be the same right? so it cancels out the original value and place new value which is 80
    What will happen if I delete all my change log as a part of my clean up process? what if later on if someone goes and modified the record from 80 to 40?  because see the original record of 100 and then -100 and 80 will be gone right?
    please help me understand this issue.thank you.

    Hi John,
    First time when you will load the data the recordmode of the record will be N...i.e. New record....
    Name Amount
    John $100
    Now next time when the Amount changed from $80 from $100....status in the Change log will be
    Name Amount
    John -$100 --> Before Image
    John $80  --> After image..
    Remember both this before and after inage will get created as a part of the same delta request....automatically....
    Suppose in the cube the value is :
    Name Amount
    John $100
    After delta load the status in the cube will be :
    Name Amount
    John $100 --> Previous loading
    John -$100 --> Before Image
    John $80  --> After image..
    So $100 and -$100  will cancel each other and the value will be $80......
    If you delete the Change log...it will not impact much untill and unless you delete the record from the ODS.....
    Because, next time when it become 80 to 40......if you load the data......
    In ODS changelog the situation will be...
    Name Amount
    John -$80 --> Before Image
    John $40  --> After image..
    As I told that both before and after image will get generated as apart of the same request..
    So, In the cube ...
    John $100 --> Previous loading
    John -$100 --> Before Image
    John $80  --> After image..
    John -$80 --> Before Image
    John $40  --> After image..
    So the final value is $40
    Regards,
    Debjani..

  • Basic Measurement  Question

    Hi
    This question seems like a simple one, but I can't seem to find an answer. We run benchmark tests of our application, and when we report the results, our customers usually ask "When you say you processed x number of business transactions, how many Oracle inserts, updates, selects, and delets does that amount to ?".
    Statspack shows a lot of sophisticated measurements, but I haven't been able to figure out how to answer that basic question.
    Any ideas?
    Thanks
    Tom Hogan

    A benchmark is a baseline for which a future comparison. Benchmarks taken in the same manner using the same procedures can be compared. The absolute values do not matter so much as the relative values which are most useful when compared over time.
    This is true even when all the details of what makes up a derived value is not known so long as the method used to derive the value is known and consistent over time. Obviously the more that is known the more uses the results can be applied to, but knowledge of every variation is not a requirement for obtaining useful information.
    Still it is important to benchmark only useful factors and for later analysis it may be necessary to store information about important details used in deriving the benchmark value. But again it is not necessary to know or save information about all the details.
    -- Mark D Powell --

  • JLabel Icon Update Question

    Hi. I have created a jLabel that get's it's Icon updated via a value derived from a MYSQL query. The Icon1 value is a URL. My question is, if I do the MYSQL query and the URL doesn't change from the existing value, does the jLabel still go out and pull the image over? Or does it recognize that the URL is still the same and doesn't make an attempt at pulling the image over? Basically, I am asking this because I'm trying to determine the load on my webserver. Thank you for your help!
    image1.setIcon(icon1);

    Hi Daryl. Here is what I'm doing:
    protected static ImageIcon createImageIcon(String URL,
                                                   String description) {
            //java.net.URL imgURL = LabelDemo.class.getResource(URL);
            java.net.URL imgURL = null;
        try {
          imgURL = new java.net.URL(URL);
        } catch (Exception e) {
          //Logger.getLogger(LabelDemo.class.getName()).log(Level.SEVERE, null, ex);
            if (imgURL != null) {
                return new ImageIcon(imgURL, description);
            } else {
                System.err.println("Couldn't find file: " + URL);
                return null;
    ImageIcon icon1 = createImageIcon("https://www.website.com/images/" + dateVal + "/thumbs/" + image2Val + "",
                       image1.setIcon(icon1);

  • JTree Updating question

    Hi there. I have two questions.
    I have a data structure that is being displayed in a JTree, so I made a Model and it works great. The data structure can be updated from non-gui interaction. The nodes don't change position or anything, its just the data that is displayed is changed. I handle it currently by calling a function in the model I made called nodesChanged(), which basically does the following:
    public void nodesChanged()
        int len = treeModelListeners.size();
        TreeModelEvent e = new TreeModelEvent(this, new Object[] {rootItem});
        for (int i = 0; i < len; i++) {
          ( (TreeModelListener) treeModelListeners.elementAt(i)).treeNodesChanged(e);
      }It does actually work, the changes are reflected in the JTree, but it seems a little expensive, and the updates to the actual data model could come at about 150 per second. To deal with that now, I just use a timer class that updates it about every 3/10's of a second, which does a pretty good job, but is there a more elegant way to do this? Something where the node is an observer of the data in the data structure (which are Observable objects)?
    The second question I have is when I do the above, sometimes the display name of the node will be larger than the value it had previously, but the Textbox (if that's what it is) doesn't grow, so I get a ... at the end.
    For example, if I have "Run" and it changes to "Stopped", it will show up as "Sto...".
    Any help would be great. TIA.

    well, you can start by making the node you put in the tree model event the lowest node in the tree that needs updating, instead of root.
    I don't know about the timer thing, cuz as far as I know, the listener will invoke code that will refresh the renderers, as opposed to painting where repaint calls can be merged into one. If you aren't getting that many updates all the time, you could implement something where the listener fires to an intermediate listener which will fire the info to the tree after a slight delay. That way if you get multiple updates, you can effectively ignore lots of them.
    The ... thing, I thought that treeNodesChanged was the appropriate method, although maybe it has to be for the specific node, not root.

  • Basic Netweaver Questions

    Could anyone plz provide the answers for this netweaver Questions.
    1. Which statement is wrong while using the update modules? 
    $V2 requests are processed successfully once V1 requests are processed
    $V2 requests are non restartable 
    $V1 requests can be restarted using SM13
    $V2 update modules are used for database changes linked   to v1 changes
    2. Which functionality does not exist in the SAP NetWeaver stack? 
    $People Integration 
    $Information Integration 
    $Distribution Integration
    $Process Integration 
    3. What is the latest generally available release of SAP’s ERP software : 
    $SAP ERP Central Component 5.0 
    $SAP R/3 4.7
    $mySAP ERP
    $mySAP R/3 Enterprise 
    4. Which SAP software provides advanced business functionality for sales planning and execution to an organization
    $SAP NetWeaver 
    $mySAP SCM 
    $mySAP ERP
    $mySAP CRM
    5. Which of the following is not a component in mySAP Business Suite but is part of mySAP ERP: 
    $SAP SCM 
    $SAP CRM 
    $SAP SEM 
    $SAP SRM 
    6. What is the basic principle of Production Planning in SAP ERP solution? 
    $MRP2 
    $CRP 
    $DRP
    $APO 
    7. What is the main tool in SAP NetWeaver that enables people integration? 
    $SAP Business One 
    $SAP Human Capital Management
    $SAP Enterprise Portal 
    $SAP Business Intelligence

    I'd answer:
    1. #4
    2. #3
    3. #1
    4. #4
    5. #3
    6. #1
    7. #3

  • Basic airport question

    I have very basic question: I connect to my home network wirelessly with a linksys router and cable modem. But the speed is very slow. If I turn off airport and connect to the router, the connection is about twice as fast as using airport. I've had my mac about two years, and maybe I need to update the software or hard ware, but don't know what I need.
    When I looked online at the support page, it showed actual hardware (looked like white routers, I guess), which I don't have. I presume I have the airport card, but I don't have a separate apple hardware thing like was shown on the apple site. so I don't really know WHAT I have. When I looked at the version on my airport menu, it showed airport version 427.1.1, firmware 429.6.0, extreme driver 405.1.0, admin util 420.31.0, setup 420.17.0
    Can anybody help me?
    Thanks, pat

    miamigrad wrote:
    I have very basic question: I connect to my home network wirelessly with a linksys router and cable modem. But the speed is very slow. If I turn off airport and connect to the router, the connection is about twice as fast as using airport. I've had my mac about two years, and maybe I need to update the software or hard ware, but don't know what I need.
    With wireless, is it's hard to troubleshoot air. If your wireless connection is slower than your wired connection, I'd suggest starting with the router. How old is it? Is it possible that it is only 802.11b compliant? If so, you can get a new one that is 802.11g or even 11.n. now as the prices are dropping on those. I would log into it anyway and check the settings. If 802.11g is available and not selected, change it.
    Are you in close range of the router when you are using wireless? Are other wireless devices connecting simultaneously? I guess it could be possible that wired takes priority over wireless in terms of how routers work, but I really don't have any idea. Maybe someone else knows about that. But as always with anything that isn't acting up to par, I would repair permissions, repair hard drive, (I don't even bother to verify, just repair) and if that doesn't fix it, then create a new user account, log in to it and compare with your regular user account.
    Also the white hardware you saw on the support site, is either the airport extreme base station or express base station, which essentially is a router with print sharing and music sharing. To my knowledge, it has no firewall built in and costs way more than a plain wireless router which is easier to set up. In other words, you don't need one for your wireless connection.

Maybe you are looking for

  • How do I upload a photo album to facebook.

    When I try to upload aa album from my iPad it only let's me do one picture at a time.  I am using the Facebook app for this.  I am wondering if there is a way to upload more than one picture at a time.  Thanks

  • Can you give suggestions on new editing hardware?

    Hi there, I try not to post at multiple places but I've already posted at CreativeCow and haven't received a response.  I'm wondering if anyone here has some suggestions for me. After searching around I came across Videoguys DIY build suggestions.  N

  • Master-detail reports in SqlDeveloper

    Hello, I recently read this article by Sue Harper. www.oracle.com/technology/oramag/oracle/07-may/o37sql.html I am using Sqldeveloper for a little while now, but never created a user-defined report. This morning I read this article about it, and I am

  • Placement and appearance digital signature

    I have a couple of questions about the placement and appearance of the digital signature. First the placement: Is it technically possible to place the digital signature after Word-fields when you convert Word to PDF/A? For example the { DOCPROPERTY "

  • Missing Effects Tab

    My Effects Tab went missing from my Browser Window. I can get it back by selecting Windows>Effects, but it superimposes over and hides the Video Tab. How do I get it to return to its proper place alongside the Video Tab?