CREATE PROCEDURE usp_EmployeeAttendance (
@Emp_No nvarchar(50),
@In_Time_Punch datetime,
@Out_Time_Punch datetime,
@Remarks nvarchar(50), @Status varchar(10),
@Att_Date date, @Hrs nchar(10), @W_Days int
)
AS
BEGIN
INSERT INTO Emp_Att (Emp_No, In_Time_Punch, Out_Time_Punch, Hrs, Status, Remarks, W_Days, Att_Date)
VALUES
(
@Emp_No,
@In_Time_Punch,
@Out_Time_Punch,
@Hrs,
@Status,
@Remarks,
@W_Days,
@Att_Date
)
IF (@In_Time_Punch > '7:25:00')
BEGIN
SET @Remarks = 'LC'
END
ELSE
IF (@In_Time_Punch = '')
BEGIN
SET @Remarks = 'IN PUNCH FORGET'
IF (@In_Time_Punch < '16:35:00')
BEGIN
SET @Remarks = 'EL'
END
ELSE
IF (@Out_Time_Punch = '')
BEGIN
SET @Remarks = 'OUT PUNCH FORGET'
END
END
END
答案 0 :(得分:0)
您可以使用VALUES
语法,而不是在INSERT
语句中使用INSERT...SELECT
。使用Remarks
表达式设置CASE
的值:
INSERT INTO Emp_Att (Emp_No, In_Time_Punch, Out_Time_Punch, Hrs, Status, Remarks, W_Days, Att_Date)
SELECT
@Emp_No,
@In_Time_Punch,
@Out_Time_Punch,
@Hrs,
@Status,
CASE
WHEN @In_Time_Punch > '7:25:00' THEN 'LC'
WHEN @In_Time_Punch = '' THEN
CASE
WHEN @In_Time_Punch < '16:35:00' THEN 'EL'
WHEN @Out_Time_Punch = '' THEN 'OUT PUNCH FORGET'
ELSE 'IN PUNCH FORGET'
END
END,
@W_Days,
@Att_Date