Tuesday, November 16, 2010

How to Update Data of One Table to Other Table

You can use the below query to Update the data of one table by comparing and update that data with another table.


UPDATE A SET myCol=B.myCol 
FROM myTable A  
INNER JOIN myOtherTable B ON A.ID=B.ID 


If you want to update the table of one database with the value of another table of another database,Use the below query.
Nothing is different from the above query with just prefix with the database name


UPDATE A SET myCol=B.myCol 
FROM myDatabase.dbo.myTable A  
INNER JOIN myOtherDatabase.dbo.myOtherTable B ON A.ID=B.ID 

No comments:

Post a Comment