Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2013
    Posts
    31

    Unanswered: Join queries from two different databases on the same server

    Hi Guys thanks for taking time to read this post I am new in SQL and I would like to request some help please
    I am using SQL 2008 r2

    I have two SQL Queries from 2 different database but they share one server. I need to linked these two SQL Queries as they share the same Primary key which CustomerID see example below


    Query 1

    Database::Student
    Select StudentID , FName, LName
    From Student


    Query 2

    Database ::Finance

    Select StudentID,Tution
    FROM Payment


    I need to be able combine two query which come from two database but they share one server.I would like to use two temp tables so that I can perform a left / right join to retrieve the data by linking two queries using primary id which they both share ( StudentID)

    Summary
    I have two DB's on the same server. I have two simple select queries for each DB which work correctly

    Thanks so much for your time.
    Last edited by john100; 05-20-14 at 21:57.

  2. #2
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Just qualify the names, see: Information Schema Views (Transact-SQL)

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Mar 2013
    Posts
    31
    Hi Pat Phelan


    Thanks for the reply any chance of using the example I have given please .

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Based on your PM repeated below:
    Quote Originally Posted by john100
    Pat Phelan

    Thanks for the reply I am still stuck with example/link you provided is it possible to use the example I have used so that I can be able understand it please. I am more of visual thinker. Thanks once again for your help
    I'd really need access to your server to be able to help. You seem to be looking for a "ready to run" solution, and I'd have to assume too many things for me to be comfortable that I could craft that for you.

    You ought to be able to extend the table names with the appropriate database and schema names (using the dotted notation described in the link I posted earlier). You've provided two of the three parts (the database and object names), but not the schemas.

    Even if I could provide you with a simple snippet of code to do what you are requesting, that probably wouldn't be a good idea. If you experiment a bit and find out which of the issues that could trip up a simple answer apply to your case (server, schema, and objects) then you'll be able to solve more problems like this at will... If I assume that there are no pitfalls or worse yet happen to guess correctly on all of them, then I've given you an answer instead of teaching you to make new answers.

    Please try to create a solution for yourself. If you have problems, come back and explain what you tried and what went wrong and I'll do what I can to help!

    -PatP
    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •