Solved

How can you connect two tables together from two different databases?

Posted on 2007-11-21
5
3,541 Views
Last Modified: 2012-08-14
I need to run a query that joins two tables from two different databases.
0
Comment
Question by:edenmachine
5 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 20328484
Select * From DatabaseOneName..TableOneName Join DatabaseTwoName..TableTwoName On some join conditions here
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20328492
prefix "databaseName.." while specifying the table



from db1.dbo.Table1 a
inner join db2.dbo.Table2 b on a.id = b.id
0
 
LVL 6

Accepted Solution

by:
messen1975 earned 125 total points
ID: 20328592
Are the two databases on the same server?  If they are are you can just specify the database name as they said above.

If they aren't you have to create a linked server:
http://msdn2.microsoft.com/en-us/library/ms188279.aspx

0
 
LVL 1

Author Closing Comment

by:edenmachine
ID: 31410384
Yes, they were in different servers so this is what I needed.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20329306
So what was the pbm with the above two comments
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now