Update record if master table record exist

  • I want to update the PO table with the BuyerName if there is a Buyer record exist.

    In below example , it should update Buyer field in PO Table with Roger James as there is a record exist for code RAJ.

    It should not update PO Table for james Kidlo as there is no Buyer code exist.

    PO Table

    PO# Buyer

    ----- ------------

    PO001 RAJ

    PO002 James Kidlo

    Buyer Table

    Buyer Name

    ------ --------------

    RAJ Roger James

    PRK Paul Kisslebeck

  • You're going to have a problem as it looks like you want to update a join key on the PO Table

    Why do you want to update the PO Table? Which column do you want to update?

  • Consider normalizing these tables in future.

    For now, Check if this works:

    Update POTable

    set Buyer = PO.Name

    FROM POTable PO inner join BuyerTable BT

    ON PO.Buyer = BT.Buyer

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

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