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 2000 Forums
 SQL Server Development (2000)
 Data correction

Author  Topic 

sqlfresher2k7
Aged Yak Warrior

623 Posts

Posted - 2007-08-22 : 10:53:43
I have two database which contains same structure.
I want to compare the data from same tables of two different databases which has same id and run an update query.

Database1
table1:

Tid pno
--- ---
1 56
2 59
3 68
4 98
5 45


Database2
table1:

Tid pno
--- ---
1 66
2 89
3 48
4 88
5 55
6 96
7 48
8 16
9 25


Output:
Database2
table1:

Tid pno
--- ---
1 56
2 59
3 68
4 98
5 45
6 96
7 48
8 16
9 25

Thanks for your help in advance!!!!!

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-08-22 : 11:00:30
[code]UPDATE t
SET pno = s.pno
FROM database2.dbo.table1 t INNER JOIN database1.dbo.table1
ON t.tid = s.tid[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

sqldba2k6
Posting Yak Master

176 Posts

Posted - 2007-08-22 : 11:38:46
Thanks KH!
Go to Top of Page
   

- Advertisement -