Solved

Making a stored proc reads from two databases?

Posted on 1998-09-09
3
197 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
bharris1 earned 60 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now