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 2005 Forums
 Express Edition and Compact Edition (2005)
 How do I run an SQL query across two databases?

Author  Topic 

Ilyas
Starting Member

1 Post

Posted - 2007-06-01 : 03:14:38
I was hoping someone could assist me. I would like to know how to structure a SQL query in an attempt to compare data across two databases?

For example:

I'd like to know when salary in one database is changed in another and if it has, then list the new salary so I was thinking of something like this:

select DB1.name, DB1.salary
From DB1.EmployeeTable, DB2.EmployeeTable
where DB1.salary <> DB2.salary

Any feedback would be great.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-01 : 03:21:06
[code]Select t1.Name, t1.Salary, t2.Name, t2.salary
From DB1..EmployeeTable t1 Join DB2..EmployeeTable t2
on t1.Pk = t2.pk and t1.salary <> t2.salary[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-01 : 08:47:55
If the user is not dbo, then specify the user also

DB1.username.EmployeeTable

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -