• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 445
  • Last Modified:

join two tables from two different databases

I have two databases - same server
I need to create a join of datasource1.customer and datasource2.payments - joined on an account number.
How would I do this .
0
Tagom
Asked:
Tagom
  • 2
2 Solutions
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Just spell out the database_name.schema.object_name

SELECT c.*
FROM datasource1.dbo.customer c
   JOIN datasource2.dbo.payments p on c.id = p.customer_id

or if the default schema is dbo, just do 'dot-dot', although this is not considered a best practice

SELECT c.*
FROM datasource1..customer c
   JOIN datasource2..payments p on c.id = p.customer_id
0
 
Barry62Commented:
SELECT datasource1.table1.customer,datasource1.table1.accountnum, datasource2.table2.payments FROM datasource1.table1 inner join datasource2.table2  ON datasource1.table1.accountnum=datasource2.table2.accountnum
0
 
Vijaya Reddy Pinnapa ReddyCommented:
SELECT datasource1.customer.field1,datasource1.customer.field2,datasource1.customer.field3,datasource1.customer.field4*, datasource2.payments *
FROM datasource1.customer INNER JOIN Orders ON datasource1.customerCustomerNo =
datasource2.payments..CustomerNO
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the split.  Good luck with your project.  -Jim
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now