update a field in table2 given condition in table1

  • I would like to update a field (dssid) in table2 with a field in table1 (dssid) given that the id field in both tables are equal and dssid in table2 is blank/NULL;

    table1

    dssid            id

    123              71

    124              31

    157              16

    756               15

     

    table2

    id                dssid

    71

    31

    16

    15

     

    What is the Tsql procedure for the above?

    Thanks,

    Allan

     

  • update t2

    set    t2.dssid = t1.dssid

    from   table1 t1

    join   table2 t2

    on     t1.id = t2.id

    and    t2.dssid is null

    .. should do it.

    -- edit

    but as with everything, test it before actually attempting to do the update.

    =;o)

    /Kenneth

  • Thanks kenneth, this has worked satisfactorily.  Once again it is greate to be in this forum.

    Allan.

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

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