SQL Join statement across two databases?

November 20, 2009 - 8:45 pm

Is there a way to create a join statement across two databases?

Using the example below..

I need to the specid column from System.dbo.PayerSpec and Data.dbo.claim

Can someone help me with this?

Thanks!

As long as both databases are part of the same SQL Server instance you can do it with a simple join.

select *
from system.dbo.PayerSpec p
inner join Data.dbo.claim c
on p.specid = c.specid

If they’re in different instances or on different servers, you want to look at setting up a linked server which lets you query between remote databases.

2 Responses to “SQL Join statement across two databases?”

  1. Serge M Says:

    select A.*, B.* from
    System.dbo.PayerSpec A, Data.dbo.claim B
    Where <…>
    References :

  2. KegC Says:

    As long as both databases are part of the same SQL Server instance you can do it with a simple join.

    select *
    from system.dbo.PayerSpec p
    inner join Data.dbo.claim c
    on p.specid = c.specid

    If they’re in different instances or on different servers, you want to look at setting up a linked server which lets you query between remote databases.
    References :

Leave a Reply