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)
 Interesting Questing

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-12 : 09:38:41
Bharath writes "Hi,


Let us take the following case
There are two servers having one database each
and i want to write a query using a INNER join or outer JOIN
to fetch data using the two databases how to do this?.

how to link the two databases?
(linked servers concept?)

please reply back on this mail i would be thrilled to get
an answer for this question


regards
Bharath"

joldham
Wiseass Yak Posting Master

300 Posts

Posted - 2002-03-12 : 10:19:22
First, you would need to create a linked server from one of the databases. Then in your SQL statement in the FROM clause, use the following syntax to select the table or view in the other database:
Servername.Databasename.owner.table

If Server2 had Database2, Table2 and the linked server was Server1 and had Database1 with Table1 the statement would look something like:

SELECT a.*, b.*
FROM Server1.Database1.dbo.Table1 a, Table2 b
Where a.ID = b.ID

etc., etc., etc.

Someone else in the forum may have a better idea. Let me know if this doesn't satisfy your questions.

Jeremy



Go to Top of Page

Onamuji
Aged Yak Warrior

504 Posts

Posted - 2002-03-12 : 13:36:54
OPENROWSET works too... but linked servers are nice too...

Go to Top of Page
   

- Advertisement -