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
 Transact-SQL (2000)
 Query two databases

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-06-10 : 09:26:40
Angie writes "For data mining purposes, I want to query from two databases.
What is the proper syntax for a query where the source
is from two dtabases.

Something like this
Example: db1 on serverX and db2 on serverY

SELECT tbl1.field1, tbl2.field2
FROM serverX:db1.tbl1 tbl1 inner join serverY:db2.tbl2 tbl2
ON tbl1.field3 = tbl3.field 3
WHERE tbl1.field3 > 0"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-06-10 : 09:36:34
You've got the syntax correct except for the colon (:), change that to a period (.) instead:

SELECT tbl1.field1, tbl2.field2
FROM serverX.db1.tbl1 tbl1 inner join serverY.db2.tbl2 tbl2
ON tbl1.field3 = tbl3.field 3
WHERE tbl1.field3 > 0


Make sure that you set up either serverX or serverY with the other server as a linked server. See Books Online for more info on linked servers.

Go to Top of Page
   

- Advertisement -