开发者

Error when using OUTPUT parameter with sp_execute

I'm having a problem with dynamic SQL and reduced my code to this simplest possible example. Why does this:

DECLARE @St开发者_开发问答atement NVARCHAR(1000), @Name SYSNAME;
SET @Statement = N'SELECT TOP 1 @Name = name from sys.objects';
EXEC sp_execute @Statement, N'@Name SYSNAME OUTPUT', @Name OUTPUT;

Get me this:

Msg 214, Level 16, State 2, Procedure sp_execute, Line 1
Procedure expects parameter '@handle' of type 'int'.

What is the correct syntax?

I also tried:

DECLARE @Statement NVARCHAR(1000), @Name SYSNAME;
SET @Statement = N'SELECT TOP 1 @NameOUT = name from sys.objects';
EXEC sp_execute @Statement, N'@NameOUT SYSNAME OUTPUT', @NameOUT = @Name OUTPUT;

But had the same errror.


I think you meant to use sp_executesql instead, since you're executing a SQL string. Compare the documentation: sp_execute vs. sp_executesql.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜