Пользовательская функция ValidateNewPW() и хранимая процедура UpdatePassword
CREATE FUNCTION ValidateNewPW (
@IDToEdit int,
@OldPassword nvarchar(44),
@NewPassword nvarchar(44),
@SuperPassword nvarchar(44) = ??)
RETURNS nvarchar(44)
AS
BEGIN
DECLARE @PWReturn AS nvarchar(44)
DECLARE @SuperPW AS nvarchar(44)
SET @SuperPW = (SELECT SuperPassword
FROM AppVariables)
IF @SuperPassword <> @SuperPW
IF @OldPassword = (SELECT Password
 FROM EmpPhones WHERE EmployeeID = @IDToEdit)
 SELECT @PWReturn = @NewPassword
ELSE
 SELECT @PWReturn = ?Failed?
ELSE
IF @SuperPassword = @SuperPW
 SELECT @PWReturn = @NewPassword
ELSE
 SELECT @PWReturn = ?Failed?
RETURN @PWReturn
END
CREATE PROCEDURE UpdatePassword
@IDToEdit int,
@NewPassword nvarchar(44),
AS
UPDATE EmpPhones
SET Password = @NewPassword
WHERE EmployeeID = @IDToEdit

Поделитесь материалом с коллегами и друзьями