Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Posts
    16

    Unanswered: Help - Updating A Field In Query Analyzer

    Hi All,

    I'm trying to create a script that updates a field in a table, based on data in another table. It should be simple, but I'm doing something wrong. Here's the code:

    USE DBMyDatabase

    UPDATE TblToBeUpdated
    SET IDField=TblOther.IDNew
    WHERE IDField=TblOther.IDOld

    SELECT Pk, IDField
    FROM TblToBeUpdated

    What am I doing wrong? The error code I get is:

    Server: Msg 107, Level 16, State 3, Line 1
    The column prefix 'TblOther' does not match with a table name or alias name used in the query.
    Server: Msg 107, Level 16, State 1, Line 1
    The column prefix 'TblOther' does not match with a table name or alias name used in the query.

    Thanks.

    Henry

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    UPDATE TblToBeUpdated
    SET IDField=TblOther.IDNew
    FROM TblToBeUpdated
    inner join TblOther on TblToBeUpdated.IDField=TblOther.IDOld
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    I very rarely use this syntax, but as I remember it:
    PHP Code:
    UPDATE tblToBeUpdated
       SET IDField 
    b.IDNew
       FROM tblToBeUpdated
       JOIN tblOther 
    AS b
          ON 
    (b.IDOld tblToBeUpdated.IDField
    should do the trick!

    -PatP

  4. #4
    Join Date
    Jan 2004
    Posts
    16
    Thanks. Works beautifully.

    Henry

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •