Coping Column Data between Tables

  • I want to copy/overwrite the date for each order in the production table from a restored table. The production table now has more orders in it than the restored table and I don't want to lose the new order dates.  The restored table is on another database but I can copy that over as a different named table. Any responses would be really appreciated! Thanks!

  • So, you want to import those rows that doesn't already exist in your production table? If so, have a look at EXISTS() in BOL. and maybe this helps, too:

    http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=172771

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • No. The rows already exist in the table (35,000 or so) I want to change the date in the already existing rows on the production Order table from the restored backup of the Order table. The production table has more rows than the restored table so I want to keep the newer order dates in it.  I have an identity seed for Order_ID,Date and other columns but I only want to update the date.

  • Ok I wasn't looking for a free ride on this site and have been looking for a solution for awhile (The BOL is big, espescially when you have other things to do!), but I think I found it:

    UPDATE a

      SET a.called = b.called

       FROM t_ORDERTEST a,t_ORDER b

        WHERE a.id = b.id

     

    Any objections??

  • I'd use ainsi compliant syntaxe but that's gonna do it :

    UPDATE a

    SET a.called = b.called

    FROM t_ORDERTEST a inner join t_ORDER b

    on a.id = b.id and a.id2 = b.id2 --assuming here you have a composite key

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply