0

我有一个存储过程,如下所示:

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 值。

任何想法我做错了什么?

提前致谢

4

3 回答 3

1

“返回”停止执行存储过程,因此第二部分永远不会执行。省略“return”语句并阅读输出变量,您已经在设置它们的值。

于 2013-03-06T10:59:34.947 回答
0

如果您使用的是输出参数,则不要使用 return 仅设置变量。前任。设置@teamID = 10

于 2013-03-06T11:02:43.740 回答
0

设置值而不是返回..

于 2013-03-06T11:02:54.893 回答