Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2004
    Posts
    7

    Unanswered: Why This SP Never Returns -2?

    CREATE PROCEDURE UpdateAccount
    (
    @AccountID int,
    @EmailAddress varchar(255),
    @Password varchar(16)
    )
    AS
    DECLARE @actualPassword varchar(16)
    SELECT @actualPassword = Password
    FROM Account WHERE AccountID = @AccountID

    If Exists( SELECT EmailAddress FROM Account
    WHERE EmailAddress = @EmailAddress )
    RETURN -1

    ELSE IF @Password <> @actualPassword
    RETURN - 2

    ELSE
    UPDATE Account
    SET
    EmailAddress = @EmailAddress,
    Password = @Password
    WHERE AccountID = @AccountID
    GO

  2. #2
    Join Date
    Nov 2004
    Location
    India
    Posts
    31

    Lightbulb

    U have not shown the code as to how u r executing this procedure. Try this. I am sure it will work:

    Code:
    declare @RetVal int
    exec @RetVal = UpdateAccount 1, 'xyz@mymail.com', 'asf'
    select @RetVal
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
    Knight says:

    You can't change the past, but you can ruin a perfectly good present by worrying about the future..

  3. #3
    Join Date
    Nov 2004
    Location
    India
    Posts
    31

    Further...

    Additionally, ur procedure will return -2 if the condition of "IF EXISTS" is false and that of "ELSE IF" is a true.
    This will be possible if while executing the procedure, u supply @AccountID
    and @Password of such a record that is present in the table but @EmailAddress should not match for that record. Hope this wiil help.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~
    Knight says:

    You can't change the past, but you can ruin a perfectly good present by worrying about the future..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •