Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Single query from 2 databases

Posted on 2006-11-29
6
Medium Priority
?
452 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 2000 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

636 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