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
 General SQL Server Forums
 New to SQL Server Programming
 How do I update data in two linked table in T-SQL?

Author  Topic 

Indra_G
Starting Member

13 Posts

Posted - 2011-11-10 : 06:04:53
I usually use MS Access database for my VB.NET program. If I want to update a data in a table (A) that is linked to another table (B), with the condition of table B, I usually use this kind of query:
Update tblA, tblB Set tblA.Date1 = Null, tblA.Date2 = Null Where tblA.Numb = tblB.NoF And tblB.Numb = 'B-0010' 

However, when I tried it with SQL Server 2005, I got incorrect syntax error. How am I supposed to do this in T-SQL?

Thank you so much...

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-10 : 06:26:04
in sql server it should be like


Update a
Set a.Date1 = Null,
a.Date2 = Null
from tblA a
join tblB b
on a.Numb = b.NoF
And b.Numb = 'B-0010'


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Indra_G
Starting Member

13 Posts

Posted - 2011-11-10 : 23:54:08
OK, that works well! Thank you so much...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-11 : 03:05:39
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -