0
我查詢更新表HumanResources.EmployeePayHistory所有記錄,而不是隻有那些更新,其中患病小時< = 20 ...SQL服務器更新查詢不能
而且我意識到某些領域正在更新超過1次。
我不一定非要使用下面的這種格式,但我必須使用while命令來完成這項工作(需求)。
我正在使用AdventureWorks2012數據庫。
DECLARE SickHours CURSOR FOR
select distinct e.BusinessEntityID, p.FirstName, p.LastName, e.JobTitle, e.SickLeaveHours,
round(eph.Rate, 2) as NewHourlyRate
from Person.Person p
inner join HumanResources.Employee e
on p.BusinessEntityID = e.BusinessEntityID
inner join HumanResources.EmployeePayHistory eph
on e.BusinessEntityID = eph.BusinessEntityID
where e.SickLeaveHours <= 20;
OPEN SickHours;
FETCH NEXT FROM SickHours;
WHILE @@FETCH_STATUS = 0
BEGIN
update HumanResources.EmployeePayHistory
set Rate = (Rate * 1.1), ModifiedDate = GETDATE()
FETCH NEXT FROM SickHours;
END;
CLOSE SickHours;
DEALLOCATE SickHours;
GO
我該如何解決?
感謝