Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Making a stored proc reads from two databases?

Posted on 1998-09-09
3
Medium Priority
?
266 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 120 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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 …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

688 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