0

i have this query and what i want to do is to execute a stored procedure from another server to get results.

i need to pass a paramenter in the sp.

my problem is that is not working and i don´t know what i have to do put this to work.

hope that someone can help me out with this.

this is my code:

 DECLARE @EXECSQL3 VARCHAR(500), @a VARCHAR(300), @b INT

SET @a = 'test'
Set @b = 100

   SET @EXECSQL3 = 'SELECT * FROM OPENROWSET
         (''xxxxx'',''xxxxxx'';''xxxxxxx'';''xxxxxxx'',
         ''[DB].[dbo].[MyStoredProcedure]  @a, @b'')'

   EXEC(@EXECSQL3)
1
  • If its a linked server can't you just execute it directly? Commented Feb 26, 2014 at 17:21

1 Answer 1

2
SELECT *
FROM OPENQUERY(OtherServer, 'EXEC db.dbo.MyStoredProcedure ''test'', 100')

I've never used OpenRowSet... but I've used OPENQUERY. I prefer it over just querying the server directly in a linked server scenario, because the query runs on the remote server, and only the results are returned, which is usually much faster.

Sign up to request clarification or add additional context in comments.

1 Comment

Can you give a little more explanation? In general, code-only answers are frowned upon as they are very specific and often hard to understand later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.