Return value in SQL Server stored procedure

前端 未结 4 876
忘掉有多难
忘掉有多难 2021-02-05 12:36

I have a stored procedure that has an if statement in it. If the number of rows counted is greater than 0 then it should set the only output parameter @UserId to 0<

4条回答
  •  春和景丽
    2021-02-05 13:02

    @EmailAddress varchar(200),
    @NickName varchar(100),
    @Password varchar(150),
    @Sex varchar(50),
    @Age int,
    @EmailUpdates int,
    @UserId int OUTPUT
    DECLARE @AA INT
    SET @AA=(SELECT COUNT(UserId) FROM RegUsers WHERE EmailAddress = @EmailAddress)
    
    IF @AA> 0
        BEGIN
            SET @UserId = 0
        END
    ELSE
        BEGIN
            INSERT INTO RegUsers (EmailAddress,NickName,PassWord,Sex,Age,EmailUpdates) VALUES (@EmailAddress,@NickName,@Password,@Sex,@Age,@EmailUpdates)
            SELECT SCOPE_IDENTITY()
        END
    
    END
    

提交回复
热议问题