Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using sp_ExecuteSQL 1

Status
Not open for further replies.

790213

Programmer
Sep 22, 2003
50
ZA
I'm busy creating a stored procedure that builds up SQL strings which I then use to execute other stored procs. Now the problem is I need the return value as well as the output parameters. So the question is:

How do I set local variables = to the return parameters of stored procs when I use sp_ExecuteSQL?

Does anyone know?
 
SET @sql = N'SELECT @m = MAX(update) FROM ' + @link_server_name + '.data1.dbo.' + @site + 'MAIN'

EXEC sp_executesql @sql, N'@m datetime OUTPUT', @MaxUpdate OUTPUT
hope this helps.
 
mimi2's answers shows how to assign values to variables using dynamic SQL. To assign SP return values, as per the original question, you can use this:

Code:
DECLARE @sql nvarchar(200),
  @ret int

SET @sql = N'EXEC @retval = myproc'

EXEC sp_executesql @sql, N'@retval int OUTPUT', @ret OUTPUT

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top