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
 General SQL Server Forums
 Script Library
 Syntax for OUTPUT parameter using sp_ExecuteSQL

Author  Topic 

Kristen
Test

22859 Posts

Posted - 2012-01-11 : 06:44:44
As its a FAQ here's an example:

DECLARE @MyOutputParameter int,
@SomeID int

SELECT @SomeID = 1234

EXEC sp_ExecuteSQL N'SELECT @MyOutputParameter = MyColumn FROM MyTable WHERE MyID = @SomeID',
N'@MyOutputParameter int OUTPUT, @SomeID int',
@MyOutputParameter = @MyOutputParameter OUTPUT,
@SomeID = @SomeID

SELECT [@MyOutputParameter]=@MyOutputParameter

Both OUTPUT parameters, in the call to sp_ExecuteSQL, are required

See also: http://support.microsoft.com/kb/262499
   

- Advertisement -