Home All Groups Group Topic Archive Search About
Author
25 Aug 2005 9:42 PM
William
Hi,

I am working with two db's and I am wondering if I can query both db in one
SP?  Basically, I am trying to extend a third party db app by adding a
custom db that holds new business data.  I need to query both dbs in a SP.
Can I do this?

Thanks

Author
25 Aug 2005 9:53 PM
Aaron Bertrand [SQL Server MVP]
Yes,


SELECT a.col1, b.col2
    FROM localdb.dbo.table1 a
    INNER JOIN otherdb.dbo.table2 b
    ON a.something = b.something



Show quote
"William" <will***@email.com> wrote in message
news:ud2gU6bqFHA.3720@TK2MSFTNGP14.phx.gbl...
> Hi,
>
> I am working with two db's and I am wondering if I can query both db in
> one SP?  Basically, I am trying to extend a third party db app by adding a
> custom db that holds new business data.  I need to query both dbs in a SP.
> Can I do this?
>
> Thanks
>
Author
25 Aug 2005 9:56 PM
Hugo Kornelis
On Thu, 25 Aug 2005 15:42:33 -0600, William wrote:

>Hi,
>
>I am working with two db's and I am wondering if I can query both db in one
>SP?  Basically, I am trying to extend a third party db app by adding a
>custom db that holds new business data.  I need to query both dbs in a SP.
>Can I do this?

Hi William,

Yes - use three-part naming:

  SELECT column1, column2, ...
  FROM   database.owner.tablename

Or, if the other database is living on a differnet server, use four-part
naming:

  SELECT column1, column2, ...
  FROM   server.database.owner.tablename


Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

AddThis Social Bookmark Button