Click here to Skip to main content
15,912,457 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi When 2 tables be in one Database, it can join2 tables of them easily.

But I have 2 Databases in SQL Server 2005. I wants to join 2 tables from these 2 Databases.
DB1 -> Table1
DB2 -> Table2



How can I do this?
Thanks very much
Posted

1 solution

Try this:
SQL
SELECT A.ID, B.Name FROM DB1.dbo.Table1 A
INNER JOIN DB2.dbo.Table2 B WHERE A.ID=B.ID

If the databases are in different servers you need to make sure that they are set up as linked servers.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900