-----------------Create a Stored Procedure update the values at runtime.-----------
CREATE PROCEDURE UpdateEmployeeId
(@empno int,@newph int, @oldph int output)
AS
SELECT @oldph=Ph FROM EmployeePersonal WHERE Emp_No=@empno
IF(@oldph=@newph)
BEGIN
RETURN 0
END
ELSE
BEGIN
UPDATE EmployeePersonal SET Ph=@newph WHERE Emp_No =@empno
RETURN 1
END
------------Execution -----------
DECLARE @oldph int
DECLARE @returnvalue int
EXEC @returnvalue=UpdateEmployeeId 101,1,@oldph OUTPUT
SELECT @oldph 'oldphonenumber'
SELECT @returnvalue 'Returning value 1 or 0'
CREATE PROCEDURE UpdateEmployeeId
(@empno int,@newph int, @oldph int output)
AS
SELECT @oldph=Ph FROM EmployeePersonal WHERE Emp_No=@empno
IF(@oldph=@newph)
BEGIN
RETURN 0
END
ELSE
BEGIN
UPDATE EmployeePersonal SET Ph=@newph WHERE Emp_No =@empno
RETURN 1
END
------------Execution -----------
DECLARE @oldph int
DECLARE @returnvalue int
EXEC @returnvalue=UpdateEmployeeId 101,1,@oldph OUTPUT
SELECT @oldph 'oldphonenumber'
SELECT @returnvalue 'Returning value 1 or 0'
No comments:
Post a Comment