Reputation: 537
I have a stored procedure as seen below:
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
My Issue is that I cannot get both return values when I execute the SPROC, I only ever get the return value of the one I put first. They both work when they are put first, but the second returns a value of NULL.
Any ideas what I am doing wrong?
Thanks in advance
Upvotes: 0
Views: 139
Reputation: 1
if you are using the output parameter then do not use the return only set the variables. ex. SET @teamID = 10
Upvotes: 0
Reputation: 39283
"Return" stops executing the stored procedure, so the second part is never executed. Leave out the "return" statements and read the output vars, you are already setting their values.
Upvotes: 1