如何在存储过程A里调用存储过程B

magicblue magicblue 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
存储过程B有3个输入参数一个输出参数,这个存储过程在每一个DB里都有

ALTER PROCEDURE [dbo].[GSP_GR_GetUserPlayedRounds]
@userID INT,
@begin DATETIME,
@end DATETIME,
@Sum INT OUTPUT
AS

BEGIN
......
END
RETURN 0

然后建立一个存储过程A,A需要在每一个DB里执行B,但我发现A往B传递输入输出参数总是有问题,执行报错:

while (@@fetch_status = 0)
begin
SET @Sql= @DataBaseName+N'Link.'+@DataBaseName +N'.dbo.GSP_GR_GetUserPlayedRounds'
exec sp_executesql @Sql, N' @userID int, @begin datetime, @end datetime, @Sum int output', @userId, @begin, @end, @Sum output
SET @RoundsNum = @RoundsNum + @Sum
fetch next from pcurr into @DataBaseName
end
close pcurr
deallocate pcurr

循环里的@DataBaseName是没有问题的,就是exec sp_executesql @Sql, N' @userID int, @begin datetime, @end datetime, @Sum int output', @userId, @begin, @end, @Sum output
这里好像不对,但是也不知道哪里错了,其中 @userId, @begin, @end是A的输入参数,@Sum是A中声明的变量
...全文

相关推荐

评论 7
收藏 已收藏
分享
返回顶部
magicblue
MS-SQL Server 34,876 成员 254,635 内容