Query Help: Replace between two tables for each row

  • I am assuming from your post TableB RecID is primary Key on that table

    UPDATE TableA Set ValueToBeReplaced = B.SomeValue

    From TableB B

    Where TableA.RecId = B.RecID

    If you are possitive that there are the same number of records and the same primary kes That's all you need, but if you need to add to A what is in B and not yet in A you will need:

    Insert TableA (fld1,fld2..)

    SELECT B.fld1,B.fld2,...

    FROM TableB B left outer join TableA A on A.RecId = B.RecId

    Where A.RecId is Null

    HTH

      


    * Noel

  • When the two tables are residing on two different databases is it not a must to prefix the database name to the table name like

    UPDATE database1.dbo.TableA Set ValueToBeReplaced = B.SomeValue

    From database2.dbo.TableB B

    Where database1.dbo.TableA.RecId = B.RecID

     

    Prasad Bhogadi
    www.inforaise.com

Viewing 2 posts - 1 through 3 (of 3 total)

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