Search code examples
sqlsql-server-2008sql-server-2008r2-express

Trying SQL table update matching on string field


Could really use some help with an update query...(SQL Serer 2008 R2 Express) I have two tables, tblJP and tblMaster.

I only have a string field that matches between the two tables.

tblJP AND tblMaster

I need to update tblJP.LangString with tblMaster.Long_text when

tblJP.short_text = tblMaster.short_text AND tblMaster.Lang = 'jp'

Any help would be greatly appreciated. I am spinning my wheels trying all sorts of logic and syntax from creating temp tables to other types of joins all with no luck.


Solution

  • A simple update with an INNER JOIN should do the trick.

    UPDATE     tblJP
    SET        tblJP.LangString = tblMaster.Long_Text
    FROM       tblJP
    INNER JOIN tblMaster ON tblMaster.alt_text = tblJP.short_text
    WHERE      tblMaster.Lang = 'jp'
    

    WARNING: Never run an update statement against your production server without first testing it against a development server - especially when someone else wrote the SQL.