R
rk_kitty
Unregistered / Unconfirmed
GUEST, unregistred user!
这是一个考勤系统中的语句,我想使in1(第一次上班的时间)为符合条件的最早时间
可SQL SERVER总是取中间的时间.
如
001 7:03
001 7:23
001 7:28
它总是取7:23,不取7:03.
重点帮忙看一下加粗的部分.
UPDATE A
SET
A.In1= CASE
WHEN (T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In1) AND T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In1))
AND ((T.Rec_Datetime<A.In1) or (A.In1 IS Null))
THEN T.Rec_datetime ELSE A.In1 END,
A.Out1= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out1) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out1)
THEN T.Rec_datetime ELSE A.Out1 END,
A.In2= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In2) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In2)
THEN T.Rec_datetime ELSE A.In2 END,
A.Out2= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out2) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out2)
THEN T.Rec_datetime ELSE A.Out2 END,
A.In3= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In3) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In3)
THEN T.Rec_datetime ELSE A.In3 END,
A.Out3= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out3) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out3)
THEN T.Rec_datetime ELSE A.Out3 END
FROM test T INNER JOIN Attend A ON A.CardNo = T.CardNo
INNER JOIN CardNo_Time C ON C.CardNo=A.CardNo
WHERE A.RecDate = @RecDate
可SQL SERVER总是取中间的时间.
如
001 7:03
001 7:23
001 7:28
它总是取7:23,不取7:03.
重点帮忙看一下加粗的部分.
UPDATE A
SET
A.In1= CASE
WHEN (T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In1) AND T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In1))
AND ((T.Rec_Datetime<A.In1) or (A.In1 IS Null))
THEN T.Rec_datetime ELSE A.In1 END,
A.Out1= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out1) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out1)
THEN T.Rec_datetime ELSE A.Out1 END,
A.In2= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In2) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In2)
THEN T.Rec_datetime ELSE A.In2 END,
A.Out2= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out2) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out2)
THEN T.Rec_datetime ELSE A.Out2 END,
A.In3= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.In3) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.In3)
THEN T.Rec_datetime ELSE A.In3 END,
A.Out3= CASE
WHEN T.Rec_datetime>DateAdd(Minute,@DecMinute,C.out3) AND
T.Rec_datetime<DateAdd(Minute,@AddMinute,C.out3)
THEN T.Rec_datetime ELSE A.Out3 END
FROM test T INNER JOIN Attend A ON A.CardNo = T.CardNo
INNER JOIN CardNo_Time C ON C.CardNo=A.CardNo
WHERE A.RecDate = @RecDate