Connecting sql server 2000 to 2 databases simultaneously

120 pts.
Tags:
SQL Server 2000
SQL Server database
I have to create a report to move inventory from an old warehouse to a new one. Each has a separate instance of the database, so I have to get the part# and location from the old warehouse and match it with the new location for that part# in the new warehouse. Is there a way to join tables from separate databases? I'm using SQL Server 2000, but have access to Visual Studio with it's Crystal Reports, if that's easier.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes you can join tables from the two databases.

Assuming that the databases are on the same server simply use the three part name of the table in the other database.

<pre>SELECT *
FROM LocalTable a
JOIN RemoteDatabase.dbo.RemoteTable b on a.PartNo = b.PartNo</pre>

If the table is on a remote instance then you need to create a linked server to the remote instance and use the four part name of the remote table.
<pre>
SELECT *
FROM LocalTable a
JOIN RemoteServer.RemoteDatabase.dbo.RemoteTable b on a.PartNo = b.PartNo</pre>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • CO Bill
    Too easy. Just what I needed - Thanks!
    120 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following