Accessing another database using a variable

120 pts.
Tags:
SELECT statement
SQL Server 2000
SQL Server database
Variables
I have a select like this:
SELECT a.part_id, a.descript, b.location from PART_MASTER a, anotherdatabase.INVENTORY b where a.part_id = b.part_id 
Is it possible to use a @variable to identify the other database, rather than hard coding it? (I've tried @db2.INVENTORY b) but SQL SERVER 2000 doesn't like that.
ASKED: October 9, 2008  4:22 PM
UPDATED: August 30, 2013  6:49 PM

Answer Wiki

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

In order to do this you have to use dynamic SQL.

Flame gave a good answer to this same question.

Discuss This Question:  

 
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

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