Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Query Syntax Joining Tables from Different Datbases Same Server

1 view
Skip to first unread message

Mike

unread,
Jun 14, 2001, 11:32:35 AM6/14/01
to
How do I code a query to join two tables from differenet databases on the
same server?

For example;

select firstname, lastname, employeeid
from dmAccounts as a
join employee e on a.employeeid = e.id
where a.component_id = 10 and a.accounttype_id = 1

dmaccounts is a table in one database and employee is in another database.
Same SQL 2000 server though.

Thanks in advance.


Grig Petrescu

unread,
Jun 14, 2001, 12:08:16 PM6/14/01
to
Mike,

If dmaccounts table is in database DB_A and table employee is in database DB_B
your select becomes:

select firstname, lastname, employeeid
from DB_A..dmAccounts as a
join DB_B..employee e on a.employeeid = e.id


where a.component_id = 10 and a.accounttype_id = 1

grig

For example;

Thanks in advance.


.

Andrew J. Kelly

unread,
Jun 14, 2001, 12:04:46 PM6/14/01
to
Use the fully qualified name like:

select a.firstname, a.lastname, a.employeeid
from dmAccounts as a
join OtherDB.dbo.employee AS e
on a.employeeid = e.id


--
Andrew J. Kelly, SQL Server MVP
Targitmail


"Mike" <mik...@enteract.com> wrote in message
news:9galjg$o7s$1...@bob.news.rcn.net...

Mike

unread,
Jun 14, 2001, 2:00:39 PM6/14/01
to
Thanks, I finally figured it out by dragging the table in EM from the into
the view designer.

"Andrew J. Kelly" <ake...@targitmail.com> wrote in message
news:O$TG7yO9AHA.492@tkmsftngp04...

Mike

unread,
Jun 14, 2001, 2:00:50 PM6/14/01
to
thanks
"Grig Petrescu" <grig.p...@histria.ro> wrote in message
news:6e2101c0f4ec$385e3090$b1e62ecf@tkmsftngxa04...
0 new messages