日期:2014-05-19  浏览次数:20453 次

问一个动态执行存储过程问题
有这么一个存储过程
_Action_UserType
@UserID   int,
@Cooperaters   nvarchar(128),
@TypeFlag   int,
@Code   int   out

这个存储过程的执行条件是存在数据库中的就是我数据库中存放
'exec   _Action_UserType   111, ' 'xx,yy ' ',1,@Code '
这么一个字符串
现在我用
declare   @ExecSQL   nvarchar(512);
declare   @AllNum   int;
set   @ExecSQL   =   'exec   _Action_UserType   111, ' '@TM,@WL ' ',1,@Code ';
exec   sp_executesql   @ExecSQL,N '@Code   int   output ',@AllNum;
print   @AllNum
这样来执行,判断是否满足条件
可是得不到@Code得输出,就是@AllNum这个值是没有
有高人指点下么?我要怎么得到_Action_UserType   存储过程里面得输出内容。


------解决方案--------------------
declare @ExecSQL nvarchar(512)
declare @AllNum int
set @ExecSQL = 'exec _Action_UserType 111, ' '@TM,@WL ' ',1,@Code out ' --这里再增加一个out
exec sp_executesql @ExecSQL,N '@Code int output ',@AllNum output
print @AllNum