Sql insert с помощью курсора для
Please i need help to resolve my cursor script. I have used the same cursor script several times and is working fine. But i do not understand this one why is not working this time. I want sum individual overtime within the period the user will provide and insert it into a new table. I have to multiply overtime by salary per hour rate from a different table. I have not added the function part of the code to sum the overtime value because is working and even if comment that part the rest of the code is not able to insert into the table and i do not get any error message. Below is the script. I be grateful to get help. Thanks in advance.
Что я уже пробовал:
Именно это я и пытался сделать.
--Tables Create Table EmployeeAttendanceRecords ( EmployeeID VarChar(10)Not Null, EmployeeName VarChar(50)Not Null, OverTime SmallInt, WorkingDate DateTime ) Create Table EmployeeDetails ( EmployeeID VarChar(10), EmployeeName VarChar(10), SalaryPerHour Money ) Create Table TestOverTime ( EmployeeID VarChar(10)Not Null, EmployeeName VarChar(50)Not Null, OverTime Money )
--Sample Data For Test EMP001,John,1,01 JAN 2020 EMP002,Linda,1,01 JAN 2020 EMP003,Mark,2,01 JAN 2020 EMP001,John,1,02 JAN 2020 EMP002,Linda,2,02 JAN 2020 EMP003,Mark,1,02 JAN 2020 EMP001,John,1,03 JAN 2020 EMP002,Linda,1,03 JAN 2020 EMP003,Mark,1,03 JAN 2020 --Salary Per Hour John = 30 Linda = 25 Mark = 27
--Stored Produre Create Proc prcTestOverTime ( @StartDate DateTime, @EndDate DateTime ) As Begin Declare @OverTimeAmount SmallInt, @EmployeeID VarChar(10) Begin Declare Cur Cursor For Select EmployeeID From EmployeeDetails Where EmployeeID = @EmployeeID Open Cur Fetch Next From Cur Into @EmployeeID While @@Fetch_Status = 0 Begin Select @OverTimeAmount = dbo.fnTestCalculateOverTime(@EmployeeID,@StartDate,@EndDate) Insert Into TestOverTime Select EmployeeID, EmployeeName, @OverTimeAmount From EmployeeAttendanceRecords Where EmployeeID = @EmployeeID And WorkingDate Between @StartDate And @EndDate Fetch Next From Cur Into @EmployeeID End Close Cur Deallocate Cur; End End