Stored procedure to update one column with different values

老子叫甜甜 提交于 2019-12-08 14:15:57

问题


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

Here is my table:

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:


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)



来源:https://stackoverflow.com/questions/12119379/stored-procedure-to-update-one-column-with-different-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!