Stored procedure to update one column with differe

2019-06-14 13:33发布

I'm having difficulties creating a stored procedure that would update rows based on employeeno, checktime and id.

Here is my table:

enter image description here

I am creating an employee attendance system. Basically we have biometrics finger scanning device to track time and stored it to database but the device was not capable of storing time as checkout it could only be checkin as shown in CheckType column.

Now I want to do is to change the Checktype column from I to O

Example :

If the employee 465-04-01 login at 7:46 am it should be recorded as I and when the same employee tries to login again at 7:47 am that same day, it should be recorded as O now, employeeno, id which is autonumber should be included since it will be the basis to update the record.

If employee logins at 4pm that same day it should be recorded as I then the next login should be O in the same day.

Can you please help me? I need a stored procedure doing this as I am not having enough experience regarding this.. please help me!

1条回答
Deceive 欺骗
2楼-- · 2019-06-14 13:54

Check for the CHECKTIME before current time each time an employee logs in

Use this type of Query in SP

    IF((SELECT(SELECT * FROM TBL_NAME
    WHERE CHECKTIME < CURRENT_TIMESTAMP and CHECKTIME > (select CONVERT(date,CURRENT_TIMESTAMP)))%2)=0)
    BEGIN
    --//HERE WRITE YOUR CODE SETTING CHECKTYPE AS 1 (EMPLOYEE ENTER)
    END
    ELSE
    BEGIN
    --//HERE WRITE YOUR CODE SETTING CHECKTYPE AS 0 (EMPLOYEE EXIT)
    END

It checks for no of times the recoeds are preasent are Even or Odd. If the count is Even, Then It returns as 1. It means the employee has ENTERED. Else If the count is Odd, Then It returns as 0. It means the employee has EXITED. (Here 0 is Even)

The value would be 1 when the value is Entered First Time (also When Third, Fifth, Seventh, ... Times) and would be 0 when the value is entered Second Time (also When Fourth, Sixth, Eighth, ... Times)

查看更多
登录 后发表回答