join two tables from two different databases

Posted on 2012-08-22
Last Modified: 2012-08-26
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 .
Question by:Tagom
    LVL 65

    Accepted Solution

    Just spell out the database_name.schema.object_name

    SELECT c.*
    FROM datasource1.dbo.customer c
       JOIN datasource2.dbo.payments p on = 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 = p.customer_id
    LVL 8

    Assisted Solution

    SELECT datasource1.table1.customer,datasource1.table1.accountnum, datasource2.table2.payments FROM datasource1.table1 inner join datasource2.table2  ON datasource1.table1.accountnum=datasource2.table2.accountnum
    LVL 9

    Expert Comment

    SELECT datasource1.customer.field1,datasource1.customer.field2,datasource1.customer.field3,datasource1.customer.field4*, datasource2.payments *
    FROM datasource1.customer INNER JOIN Orders ON datasource1.customerCustomerNo =
    LVL 65

    Expert Comment

    by:Jim Horn
    Thanks for the split.  Good luck with your project.  -Jim

    Featured Post

    Live: Real-Time Solutions, Start Here

    Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

    Join & Write a Comment

    Suggested Solutions

    Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    732 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

    22 Experts available now in Live!

    Get 1:1 Help Now