我有一个存储过程,如下所示:
ALTER PROCEDURE [dbo].[CreateNewLeague]
-- Add the parameters for the stored procedure here
@UserId uniqueidentifier,
@LeagueName VARCHAR(256),
@leagueId Int OUTPUT,
@teamId Int OUTPUT
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT @teamId = [teamID] FROM [UserTeam] WHERE (userID = @UserId)
RETURN @teamID
END
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO League([leagueAdminID], [leagueName]) VALUES (@UserId, @LeagueName)
SELECT SCOPE_IDENTITY()
Set @leagueId = SCOPE_IDENTITY()
RETURN @leagueId
END
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
INSERT INTO LeagueTeam([leagueID], [teamID]) VALUES (@leagueId, @teamID)
END
我的问题是,当我执行SPROC时,我无法获得两个返回值,我只得到我先放置的返回值。它们都放在第一个时工作,但第二个返回NULL值。
任何想法我做错了什么?
提前致谢
答案 0 :(得分:1)
“Return”停止执行存储过程,因此第二部分永远不会执行。省略“return”语句并阅读输出变量,你已经设置了它们的值。
答案 1 :(得分:0)
如果使用输出参数,则不要使用仅返回设置变量。 恩。 SET @teamID = 10
答案 2 :(得分:0)
设置值而不是返回..