Update with inner join?

  • Quick question: I have two table variables and need to perform an update on one of them based on the contents of the other. Can I perform an UPDATE operation that contains an inner join? If so, what would the syntax look like?

    Thanks.


    Regards,
    Bob Szymanski
    Blue Mule Software

  • From the FROM clause down, updates with joins look pretty much like what you'd find in a SELECT...

     UPDATE t1

        SET somecol =t2.somecol

       FROM @Table1 t1,

            @Table2 t2

      WHERE t1.someothercol = t2.someothercol

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thanks Jeff, that's exactly what I needed.


    Regards,
    Bob Szymanski
    Blue Mule Software

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

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