Update table.column with another table.column with common joined column

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2010-06-09T19:32:26Z Indexed on 2010/06/09 19:42 UTC
Read the original article Hit count: 436

Filed under:
|
|

Hit a speed bump, trying to update some column values in my table from another table.

This is what is supposed to happen when everything works

  1. Correct all the city, state entries in tblWADonations by creating an update statement that moves the zip city from the joined city/state zip field to the tblWADonations city state

TBL NAME | COLUMN NAMES

  1. tblZipcodes with zip,city,State
  2. tblWADonations with zip,oldcity,oldstate

This is what I have so far:

 UPDATE    tblWADonations
 SET              oldCity = tblZipCodes.city, oldState = tblZipCodes.state
 FROM         tblWADonations INNER JOIN
                  tblZipCodes ON tblWADonations.zip = tblZipCodes.zip
 Where oldCity <> tblZipcodes.city;

There seems to be easy ways to do this online but I am overlooking something. Tried this by hand and in editor this is what it kicks back.

Msg 8152, Level 16, State 2, Line 1 String or binary data would be truncated. The statement has been terminated.

Please include a sql statement or where I need to make the edit so I can mark this post as a reference in my favorites. Thanks!

© Stack Overflow or respective owner

Related posts about sql

Related posts about mysql