如何使用存储过程在一个特定日期添加额外小时数

时间:2017-03-02 08:37:11

标签: sql-server

ALTER PROCEDURE [dbo].[USP_HR_SelectLast_Attendance_Master]
AS                                    
BEGIN 

    DECLARE @EmployeeId varchar(50),
         @CheckIn datetime,
         @CheckOut datetime

     SELECT @EmployeeId = EmployeeId,@CheckIn=CheckIn,@CheckOut=CheckOut from Cygnus_HR_Employee_Attendance_Master where Id=IDENT_CURRENT('Cygnus_HR_Employee_Attendance_Master')
        if(@CheckIn==getdate(). && @CheckOut is NULL)
        {
            Update Cygnus_HR_Employee_Attendance_Master set @CheckOut=@CheckIn.addHours(4) where EmployeeId = @EmployeeId and CheckOut=is NULL
        }

    END

1 个答案:

答案 0 :(得分:1)

使用

SET @CheckOut = DATEADD(HH,4,@CheckIn)