How do i update this?

  • I have two tables.

    To make it simple, the table dutyrostershift has two relewant fields field "ID" and MTID_ID

    The table mTidClockInClockOut has two relevant fields External_ID and MTID_ID

    External_ID in mTidClockinout equals ID in ID in dutyrostershift.

    I want to update dutyrostershift.MTID_ID with mTidClockInOut-mtid_ID where dbo.dutyrostershift.ID = dbo.mTidClockInOutRecord.externalId

    I can find the relevant fields to update with

    select dutyrostershift.mtid_id from dutyrostershift

    join mTidClockInOutRecord ON mTidClockInOutRecord.externalid = dutyrostershift.ID

    WHERE dbo.dutyrostershift.ID = dbo.mTidClockInOutRecord.externalId

    But how to update is the question.

    please help!

    Best regards

    Edvard Korsbæk

  • Pretty simple, if you can select, you can update.

    Generic code sample

    UPDATE

    A

    SET

    A.foo = B.bar

    FROM

    TableA A

    JOIN

    TableB B ON A.col1 = B.colx

    WHERE

    ........

    Andrew SQLDBA

  • Thanks!

    And good to have it as a 'Generic'.

    Best regards

    Edvard Korsbæk

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

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