当前位置: 动力学知识库 > 问答 > 编程问答 >

SQL Server 2005: Transfer data from one table to other

问题描述:

I'm trying to update my tables and move the data from table "User" with a "Pass" column to table "Partners" to a column with the same name "Pass". i tryed a lot fo things and i give up now. i need your help! the code i am using is this one:

 UPDATE [databasename].[dbo].[Partners]

SET [Pass] = [User].[Pass]

WHERE [Code] = [User].[Code]

UPDATE [databasename].[dbo].[User]

SET [Pass] = [Partners].[Pass]

WHERE [Pass] = [Partners].[Pass]

but im getting this error:

Msg 170, Level 15, State 1, Line 3

Line 3: Incorrect syntax near 'Pass'.

网友答案:
UPDATE P
SET    [Pass] = U.[Pass]
FROM   [databasename].[dbo].[Partners] P
       JOIN [databasename].[dbo].[User] U
           ON U.[Code] = P.[Code]
网友答案:

You need to learn some basic SQL Server syntax:

UPDATE P
    SET  P.Pass = U.Pass
    FROM       [nima08].[dbo].[Partners] P
    INNER JOIN [nima08].[dbo].[User]     U ON P.Code = U.Code

UPDATE U
    SET   U.Pass = P.Pass
    FROM       [nima08].[dbo].[User]     U
    INNER JOIN [nima08].[dbo].[Partners] P ON U.Pass = P.Pass
分享给朋友:
您可能感兴趣的文章:
随机阅读: