Results 1 to 8 of 8

Thread: Multiple Join To Different DB

Hybrid View

  1. #1
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Multiple Join To Different DB

    Whenever I am going to do cross database joins, I use the little trick in QUERY ANALYZER where you RIGHT CLICK on the TABLE, drag it into the QUERY pane and let go of the mouse. Choose SELECT from the drop-down menu.

    Doing that gets you the fully qualified name of the database - one that is guaranteed to work.

  2. #2

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Multiple Join To Different DB

    Hi Guys! Thanks for the help so far! Ok to take your sample bruce with the pubs/northwind databases, here's what i'm trying to do:
    Select employee.fname, employee.lname,
    jobs.job_id,
    db2.lastname
    From Employee
    Inner Join Northwind..Employees DB2 On db2.employeeid = Employee.job_id
    RIGHT OUTER JOIN Northwind..Employees DB3 on db2.employeeid = jobs.job_id

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

    Thread Starter
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Re: Multiple Join To Different DB

    Ok got it thanks! Here's the sort of thing i was trying to get. Many thanks again for those suggestions to help me find this! Much appreciated!
    SELECT DB1_tbl1.[job_id], DB1_tbl2.[lorange]
    FROM [pubs]..[jobs] AS DB1_tbl1
    INNER JOIN [Northwind]..[Employees] AS DB2_tbl1 ON DB1_tbl1.[job_id] = DB2_tbl1.[employeeid]
    LEFT OUTER JOIN [pubs]..[roysched] AS DB1_tbl2 ON DB2_tbl1.[employeeid] = DB1_tbl2.[lorange]

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

Posting Permissions

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



Click Here to Expand Forum to Full Width