Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Multiple Databases within SQL Server

Status
Not open for further replies.

stapet

Programmer
Mar 20, 2003
22
US
I am a newbie at programming with SQL Server 2000. I am wondering, is it possible to Query more than one database at a time within SQL Server? Any help would be greatly appreciated.
The whole purpose: I would like to report off of two different databases without having the tables stored in both places.
Thanks in advance to anyone that can help!
 
You can create a view from the other database and query the view.
 
You can connect a second, third, fourth...nth...database by using dbname..tablename..columname
 
I have tried to connect to a second database, but keep getting an error message. Am I doing this correctly?

Use database1
Select f_name
From Table1
Where f_name IN
(Select database2.table2.fname)

Thank again for the help!
 
When you use the 'fully qualified' naming convention, you either need the database owner or double dots between the database name and the table.


Syntax: server.database.owner.table
or
server.database..table

If the server is the same, you don't need to include it.

-SQLBill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top