Is it possible to create a stored procedure that process data from different DBs (1 Viewer)

accesser2003

Registered User.
Local time
Today, 19:54
Joined
Jun 2, 2007
Messages
124
I would like to write a stored procedure that insert data from table [SourceEvents] located at a DB linked to DSN called CARDAX into another table [AllAttendanceEvents] located at the same DB of the stored procedure, which this DB is linked to a DSN called BAHRAIN.

If both tables are located at the same databases, the stored procedure will be as follow

Create Stored Prcoedure SP1 AS

INSERT INTO dbo.AllAttendanceEvents.*
SELECT dbo.SourceEvents.*
FROM dbo.SourceEvents


But how it will be if the case as explained above??

Thanks,
 

Banana

split with a cherry atop.
Local time
Today, 09:54
Joined
Sep 1, 2005
Messages
6,318
If you google for 'SQL Clause IN' you may get an idea...
 

accesser2003

Registered User.
Local time
Today, 19:54
Joined
Jun 2, 2007
Messages
124
Banana you always dont got what I am looking for.

However, thanks.
 
Local time
Today, 11:54
Joined
Mar 4, 2008
Messages
3,856
A natural misunderstanding since this is in the general forum.

You can reference a database in the same server by pre-pending the database name to the table name. Here is a highly modified sample (that works) from my database:
Code:
USE [ProductionDB];
GO
 
select * from x where x_ClientID not in 
(select y_ClientID from [SandboxDB].dbo.y)
GO

You'll need to make sure you have the right references on the server.
 

accesser2003

Registered User.
Local time
Today, 19:54
Joined
Jun 2, 2007
Messages
124
Thanks Mr. georgedwilkinson.

However, Unfortunatelly the another database is located in different server. If I only put the database name, it will not find it as it thinks its in the same database. Correct? For this reason I had clarify my question by mentioning the DSN Name which refers to different server database.


Please help
 

Banana

split with a cherry atop.
Local time
Today, 09:54
Joined
Sep 1, 2005
Messages
6,318
Now I know why I remembered it as "IN" clause.... This is the syntax you want.

Code:
SELECT * FROM
[ODBC;DRIVER=SQL Server;
SERVER=T02ADN01;
UID=xxxx;
PWD=xxxx;
DATABASE=xxxx;
Network=DBMSSOCN].tblAreas

{Which is about the same as an IN clause, accept you have to ability to JOIN tables from completely different sources ... which I think is really cool to do when trying to sync databases.}

That was from Brent in another thread, which was what I was thinking of when I told you to look up the IN clause.
 

Users who are viewing this thread

Top Bottom