Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update table in sql server

Author  Topic 

JohnDW
Starting Member

45 Posts

Posted - 2013-12-02 : 08:31:38
I have 2 tables: table1 with columns column1(PK,int,notnull),column2(nvarchar(30),null),column3(smallint,null)
table2 with columns column1(nvarchar(40),null),column2(smallint,null).

I want to update table1.column2 with the data from table2.column1
where table1.column3 = table2.column2
I have an updatequery like this:
UPDATE
table1
SET
table1.column2 = table2.column1
FROM
table1
INNER JOIN
table2
ON
table1.column2 = table2.column1
WHERE
table1.column3 = table2.column2

But this doesn' work.
Any advice?
John



if you do not try, it will not work

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-12-02 : 09:34:04
UPDATE table1
SET column2 = table2.column1
FROM table1
INNER JOIN table2
ON table1.column3 = table2.column2


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

JohnDW
Starting Member

45 Posts

Posted - 2013-12-02 : 10:23:57
Yes!

Txs A LOT!

John

if you do not try, it will not work
Go to Top of Page
   

- Advertisement -