Mauro
Mauro

Reputation: 2070

Execute sybase stored procedure as linked server procedure sql server 2008

EDIT


The final goal is to call a stored procedure hosted in sybase with input and output parameters from SQL Server 2008 via Linked Server


I think title is pretty clear.

My goal is to execute a stored procedure hosted in Sybase SQL Anywhere 8 in SQL Server 2008 through the linked server I already created.

Any SQL query made through the linked server is working. In addition I was able to execute a function but I don't now how to get the return value like that

EXEC ('CALL "dbname"."procedurename"(''param1'', ''param2'', ''param3'')') AT LinkedServerAlias;

Thanks 4 all your help!

Mauro

Upvotes: 1

Views: 8271

Answers (3)

gbn
gbn

Reputation: 432271

4 part object names are valid only for SQL Server linked servers.

You have to have your EXEC inside an OPENQUERY

SELECT * FROM OPENQUERY([LinkedServer], 'EXEC MyDB.MyScheme.MyProc.spname @p1, @p2, @p3')

Now, you can't parametrise OPENQUERY calls so you have use dynamic SQL

DECLARE @sql nvarchar(4000), @linkedsql nvarchar(4000)

SET @sql = 'EXEC MyDB.MyScheme.MyProc.spname ' + CAST(@p1value as int) + ...
SET @linkedsql = 'SELECT * FROM OPENQUERY(LinkedServer, ''' + @sql + ''')'

EXEC (@linkedsql)

Upvotes: 0

Mauro
Mauro

Reputation: 2070

I was finally able to do it by calling

SELECT * FROM OPENQUERY([LinkedServer], 'SELECT "dbname"."spname"(@p1,@p2, @p3)')

I'll add comments and example as soon as I experiment it.

Upvotes: 1

Piotr Rodak
Piotr Rodak

Reputation: 1941

can you use four part naming convention?

like

exec LinkedServerName.dbname.dbo.procedurename @param1, @param2, @param3

Upvotes: 1

Related Questions