Solved

Single query from 2 databases

Posted on 2006-11-29
6
447 Views
Last Modified: 2008-02-01
Hi,

I am using SQL 2005

If I have 2 database

say database1 and database2

In database1 I have table1 and in database2 I have table 2

can I make query like this

select table1.field1, table1.field2, table2.field1, table2.field2 from dba.dbo.database1.table1 as table1 inner join dba.dbo.database2.table2 as table2

I mean can I make query from 2 databases

It gives me error saying that

Msg 7202, Level 11, State 2, Line 1
Could not find server 'DBA' in sysservers. Execute sp_addlinkedserver to add the server to sysservers.

Can anyone help me

Kind Regards
0
Comment
Question by:dinesh_bali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18036371
> from dba.dbo.database1.table1
the syntax is servername.databasename.username.tablename.

so, I guess that there is some confusion?
assuming that both databases are on the samer server/instance:
from database1.dbo.table1 table1 inner join database2.dbo.table2 as table2

0
 
LVL 28

Expert Comment

by:imran_fast
ID: 18036399
dba.dbo.database2.table2

servername.databasename.ownername.tablename

dba.database2.dbo.table2
0
 
LVL 20

Expert Comment

by:Sirees
ID: 18036421
Are both databases on the same server?

If not, you need to add a linked server.
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18036430
ur other server should be linked server
u must first add the server as  a linked server and then run the queries posted aboveif it's a one time job then u could use
openquery
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18036449
opendatasource i mean

SELECT   *
FROM      OPENDATASOURCE(
         'SQLOLEDB',
         'Data Source=ServerName;User ID=MyUID;Password=MyPass'
         ).Northwind.dbo.Categories
0
 
LVL 29

Expert Comment

by:Gautham Janardhan
ID: 18036460
to use open query
first add linked server
EXEC sp_addlinkedserver 'OracleSvr',
   'Oracle 7.3',   'MSDAORA',
   'ORCLDB'
GO
and then use open query or the querie posted above
SELECT *
FROM OPENQUERY(OracleSvr, 'SELECT name, id FROM joe.titles')
GO

0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question