declare NVacation cursor for select startTime,endTime,LeaveType from NationalVacation
--NationalVacation表有三条记录
open NVacation
declare @stratTime datetime,@endTime datetime,@LeaveType int
fetch next from NVacation into @stratTime,@endTime,@LeaveType
while @@fetch_status=0
begin
fetch next from NVacation into @stratTime,@endTime,@LeaveType
update EmployeesAttendance set EmployeesStatus=@LeaveType where DateMonths between @stratTime and @endTime
--这条更新语句为啥只更新了一条语句的条件.其它两条没有更新
print @@rowcount
end
close cur --关闭游标
deallocate cur --释放游标 ------解决方案-------------------- try this,
declare @stratTime datetime,@endTime datetime,@LeaveType int
declare NVacation scroll cursor for
select startTime,endTime,LeaveType
from NationalVacation
open NVacation
fetch first from NVacation into @stratTime,@endTime,@LeaveType
while(@@fetch_status<>-1)
begin
update EmployeesAttendance set EmployeesStatus=@LeaveType where DateMonths between @stratTime and @endTime
print @@rowcount
fetch next from NVacation into @stratTime,@endTime,@LeaveType
end