Query from two db's simultaneous

Query from two db's simultaneous

Post by Tor Inge Risla » Wed, 11 Apr 2001 04:37:05



Hi, I have two db's in my MS SQL server which I want to adress in the same
stored procedure.

From a stored prosedure in DB1 I want to compare value's in DB2.

The question is therefor,  if it is possible, how do I refere to a field in
DB2

T.I. Rislaa

 
 
 

Query from two db's simultaneous

Post by BP Margoli » Wed, 11 Apr 2001 04:55:23


Tor,

Use the fully qualified table names:

use pubs
go

select *
from authors as a
join Northwind.dbo.Employees as e
  on (a.au_fname = e.FirstName)

----------------------------------
BP Margolin
Please reply only to the newsgroups.
When posting, inclusion of SQL (CREATE TABLE ..., INSERT ..., etc.) which
can be cut and pasted into Query Analyzer is appreciated.



Quote:> Hi, I have two db's in my MS SQL server which I want to adress in the same
> stored procedure.

> From a stored prosedure in DB1 I want to compare value's in DB2.

> The question is therefor,  if it is possible, how do I refere to a field
in
> DB2

> T.I. Rislaa


 
 
 

Query from two db's simultaneous

Post by Andrew J. Kell » Wed, 11 Apr 2001 04:53:33


Fully qualify the object like:

SELECT * FROM DB.owner.Object

--
Andrew J. Kelly
Targitmail.com



Quote:> Hi, I have two db's in my MS SQL server which I want to adress in the same
> stored procedure.

> From a stored prosedure in DB1 I want to compare value's in DB2.

> The question is therefor,  if it is possible, how do I refere to a field
in
> DB2

> T.I. Rislaa

 
 
 

Query from two db's simultaneous

Post by Wayne Snyde » Wed, 11 Apr 2001 07:59:58


You simply use the 3 parts of  the 4-part naming convention..

select db2.dbo.table.column from whatever...

--
Wayne Snyder MCSE, MCDBA, SQL Server MVP
IKON Education Services, C*te, NC
(Please respond ONLY to newsgroups)