创建名为“Update_EMP_Sal”的存储过程,以员工号和修改后的工资为参数,保证修改后的工资在职位允许的工资范围之内,并且与原工资的差值在10%范围内,否则取消操作,并说明原因
时间: 2024-12-17 13:43:05 浏览: 7
创建名为"Update_EMP_Sal"的存储过程,通常涉及SQL语言,其伪代码可能如下:
```sql
CREATE PROCEDURE Update_EMP_Sal (@EmployeeID INT, @NewSalary DECIMAL(10, 2))
AS
BEGIN
DECLARE @CurrentSal DECIMAL(10, 2);
DECLARE @PositionMaxSalary DECIMAL(10, 2);
DECLARE @DifferenceRatio DECIMAL;
-- 查询当前工资
SELECT @CurrentSal = Salary INTO @CurrentSal FROM Employees WHERE EmployeeID = @EmployeeID;
-- 获取员工职位的最大允许工资
SELECT @PositionMaxSalary = PositionMaxSalary INTO @PositionMaxSalary FROM JobTitles WHERE TitleID IN (SELECT TitleID FROM Employees WHERE EmployeeID = @EmployeeID);
-- 计算新旧工资差异比例
SET @DifferenceRatio = ABS(@NewSalary - @CurrentSal) / @CurrentSal;
IF @NewSalary BETWEEN @CurrentSal AND @PositionMaxSalary AND @DifferenceRatio <= 0.1
BEGIN
-- 更新员工工资
UPDATE Employees SET Salary = @NewSalary WHERE EmployeeID = @EmployeeID;
SELECT '成功更新员工工资' AS Result;
END
ELSE
BEGIN
-- 取消操作并给出原因
SELECT '新工资超出职位允许范围或与原工资的差值超过10%,操作已取消';
END
END;
```
阅读全文