Dimitar
Dimitar

Reputation: 1928

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'.

Upvotes: 0

Views: 39

Answers (2)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18411

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

Upvotes: 3

Code Different
Code Different

Reputation: 93141

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

Upvotes: 1

Related Questions