Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Can I do this?

Author  Topic 

PeterG
Posting Yak Master

156 Posts

Posted - 2004-02-10 : 12:39:15
I want to create a stored proc that would select from serverA.db.table and if record exists, insert a record in serverB.db.table. Both servers are on the network.

Create Stored procedure ...

IF EXISTS (Select 1 From serverA.db.table where field1 = '12345')

PeterG
Posting Yak Master

156 Posts

Posted - 2004-02-10 : 12:44:37
Ok, there is a stored procedure in server B that I can call. My stored proc would now be:

IF EXISTS (Select 1 From serverA.db.table where field1 = '12345')
EXEC serverB.db.dbo.StoredProc param1, param2, param3 ...

Is syntax correct?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-10 : 12:46:05
Did you set up a linked server?



Brett

8-)
Go to Top of Page

PeterG
Posting Yak Master

156 Posts

Posted - 2004-02-10 : 13:05:33
Thanks Brett,

Do I exec sp_addlinkedserver in my stored proc, before I exec the stored proc?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-10 : 13:33:01
Its a 1 time setup thing...don't forget to use sp_addlinkedsrvlogin

The reference the table using the 4 part naming convention...look in BOL



Brett

8-)
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-02-10 : 13:45:41
Actually...

You need to do a call...and use ODBC...

Look up Remote stored procedure call in BOL

Part of BOL

quote:

Calling a Stored Procedure
The Microsoft® SQL Server™ ODBC driver supports both the ODBC CALL escape sequence and the Transact-SQL EXECUTE statement for executing stored procedures; the ODBC CALL escape sequence is the preferred method. Using ODBC syntax enables an application to retrieve the return codes of stored procedures and the SQL Server ODBC driver is also optimized to use a protocol originally developed for sending remote procedure (RPC) calls between SQL Servers. This RPC protocol increases performance by eliminating much of the parameter processing and statement parsing done on the server.

The ODBC CALL escape sequence for calling a procedure is:

{[?=]call procedure_name[([parameter][,[parameter]]...)]}






Brett

8-)

EDIT Also check out

BEGIN DISTRIBUTED TRANSACTION

In BOL...there's an example there...

Go to Top of Page
   

- Advertisement -