Simple UPDATE Question

  • I think this is an easy question, and will expose

    my expertise (well ok lack of expertise).

    I have two tables.  I'd like to update BalanceTable.Vendor

    with VendorCodeTable.Vendor.  So all the rows in the

    Vendor field will have 01.

    My attempt did not work, LOL.  I realize I could just do

    Set Vendor = '01'  ... this is an oversimpified example

    of something else I'm trying to do.

    UPDATE BalanceTable

    Set Vendor = VendorCodeTable.Vendor

    FROM BalanceTable

    BalanceTable:

    AcctNo     Balance     Vendor

    1001       100         NULL  

    1002       100         NULL

    1003       100         NULL

    VendorCodeTable:

    Vendor

    01

      

  • Almost right

    UPDATE BalanceTable

    Set Vendor = VendorCodeTable.Vendor

    FROM VendorCodeTable

    You can optionally add a where clause after to do joins e.g.

    UPDATE BalanceTable

    Set Vendor = VendorCodeTable.Vendor

    FROM VendorCodeTable

    WHERE BalanceTable.Region=VenderCodeTable.Region

    HTH

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Almost is probably the story of my life

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

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