1
我寫了下面的存儲過程:爲什麼在這個select語句中沒有設置變量?
ALTER PROCEDURE [dbo].[sp_Accounts_ValidateLogin]
@EmailAddress varchar(255),
@Password varchar(20)
AS
DECLARE @UserID int
SELECT @UserID = UserID
FROM Accounts_Users
WHERE EmailAddress = @EmailAddress and Password = @Password
IF @UserID != NULL
RETURN @UserID
ELSE
RETURN -1
當執行這個程序就說明,
No rows affected.
(0 row(s) returned)
@RETURN_VALUE = -1
但每當我重寫SELECT
語句,
SELECT UserID
FROM Accounts_Users
WHERE EmailAddress = @EmailAddress and Password = @Password
結果是:
UserID
---------------------------------------------------------------------------------------
3
No rows affected.
(1 row(s) returned)
@RETURN_VALUE = -1
我的問題是爲什麼變量@UserID
是沒有設置裏面的第一選擇聲明?