Re: Stored procedure question

From: Nikolay Petrov (johntup2_at_mail.bg)
Date: 08/20/04


Date: Fri, 20 Aug 2004 09:30:13 +0300

Kind of easy ;-)
I wonder how I didn't manage to see it ;-)

Thank you Narayana

"Narayana Vyas Kondreddi" <answer_me@hotmail.com> wrote in message
news:%23sUElynhEHA.1356@TK2MSFTNGP09.phx.gbl...
> Update Users
> SET Password = @NewPasssword
> where UserID = @UserID
> AND Password = @OldPassword
>
> The above will update only if both user id and password match with a row.
>
> You could capture the rowcount after this, using @@ROWCOUNT. Based on it
> being 0 or 1 you could return a status of your choice, using RETURN
> statement.
> --
> HTH,
> Vyas, MVP (SQL Server)
> http://vyaskn.tripod.com/
>
>
> "Nikolay Petrov" <johntup2@mail.bg> wrote in message
> news:%238Yk%23pnhEHA.3928@TK2MSFTNGP11.phx.gbl...
> I need to write a stored procedure which changes user password based on
> validity of his old password.
>
> My table with users contains this columns:
> UserID - int (unique)
> Username - nvarchar(20)
> Password - nvarchar(20)
>
> I can easy change the password by using:
> CREATE PROCEDURE dbo.ChangePassword
> @UserID
> @NewPassword
> @OldPassword
> AS
> Update .Users
> SET Password = @NewPasssword
> where UserID = @UserID
> But I want the procedure to check if the @OldPassword matches the one,
> stored in the table, and only then to change it.
> Also I want the procedure to return to my app a status if the chenge has
> occured or not.
>
> TIA
>
>
>



Relevant Pages

  • Re: Can @@ROWCOUNT return NULL?
    ... from the stored procedure. ... > Immediately after each statement I save the value returned by @@ROWCOUNT to ... it appears that in SQL Server ... This is not the case here - the only DML queries are INSERTs into ...
    (comp.databases.ms-sqlserver)
  • Re: TOP statement doesnt accept a variable
    ... DECLARE @rowcount INT ... SET ROWCOUNT @rowcount ... > The following stored procedure is designed to return the ...
    (microsoft.public.sqlserver.programming)
  • Re: Error handling in stored procedure AND checking
    ... Just because your SQL statement attempts to update ... If you really do want to get an error when invalid SSN update is attempted, ... The @@ROWCOUNT function returns the number of rows affected by the last ... Inside the stored procedure, just after the UPDATE check if rows have ...
    (comp.databases.ms-sqlserver)
  • Can @@ROWCOUNT return NULL?
    ... I am troubleshooting a relatively large stored procedure with ... Immediately after each statement I save the value returned by @@ROWCOUNT to ... Before doing any further troubleshooting, I would like to rule out the ... it appears that in SQL Server ...
    (comp.databases.ms-sqlserver)