Question

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

Was it helpful?

Solution 2

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.

OTHER TIPS

can you use four part naming convention?

like

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

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top