Solved

Making a stored proc reads from two databases?

Posted on 1998-09-09
3
254 Views
Last Modified: 2010-03-19
I have a one big database on the SQL Server, and a new small database that I've created recently. I am creating some stored procedures in the new database and in those stored proc I need to join a table from the new db with a table in the old db. I tried to include "USE OLD" with the stored proc but it didn't accept it. IS there a way to do this in SQL? or is there a way around that? any help is appreciated.
0
Comment
Question by:khal
[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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
bharris1 earned 60 total points
ID: 1089981
You simply need to qualify the tables with their databases in your query.

SELECT * FROM OLD..Table1 OLD, NEW..Table2 NEW WHERE OLD.Field1 = NEW.Field1


0
 

Author Comment

by:khal
ID: 1089982
It still doesn't accept that, it is saying "invalid object name OLD..Table1". I tried to use FROM OLD..table1
also I tried  FROM OLD.table1 (one dot) but both are not working. Am I doing something wrong?
0
 
LVL 1

Expert Comment

by:bharris1
ID: 1089983
Try this:

SELECT * FROM OLD.dbo.Table1 OLD, NEW.dbo.Table2 NEW WHERE OLD.Field1 = NEW.Field1

I forgot to add the owner field  [database].[owner].[table]

0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

739 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