开发者

Error when using OUTPUT parameter with sp_execute

开发者 https://www.devze.com 2023-03-29 05:59 出处:网络
I\'m having a problem with dynamic SQL and reduced my code to this simplest possible example. Why does this:

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

精彩评论

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