Solved

Making a stored proc reads from two databases?

Posted on 1998-09-09
3
247 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
I have a large data set and a SSIS package. How can I load this file in multi threading?
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…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

740 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