SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update table in sql server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

JohnDW
Starting Member

Belgium
25 Posts

Posted - 12/02/2013 :  08:31:38  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3355 Posts

Posted - 12/02/2013 :  09:34:04  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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

Belgium
25 Posts

Posted - 12/02/2013 :  10:23:57  Show Profile  Reply with Quote
Yes!

Txs A LOT!

John

if you do not try, it will not work
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000