日期:2014-05-17 浏览次数:20561 次
SELECT WorkID, MIN(atd_datetime) atd_datetime, '上班' type, CASE WHEN datepart(hh,
MIN(atd_datetime)) > 8 THEN '迟到' ELSE '正常' END AS remark,
Employee_Name
FROM (SELECT workid, CONVERT(datetime, atd_datetime) atd_datetime
FROM Attendance
WHERE Year(Atd_Datetime) = '2013' AND Month(Atd_Datetime) = '6') A JOIN
Employee aa ON workid = aa.sn
GROUP BY WorkID, CONVERT(varchar, atd_datetime, 23), Employee_Name
HAVING datepart(hh, MIN(atd_datetime)) < 12
UNION ALL
SELECT WorkID, MAX(atd_datetime) atd_datetime, '下班' type,
CASE WHEN CONVERT(varchar(12), MAX(atd_datetime), 108)
> '17:30:00' THEN '正常' ELSE '早退' END AS remark, Employee_Name
FROM (SELECT workid, CONVERT(datetime, atd_datetime) atd_datetime
FROM Attendance
WHERE Year(Atd_Datetime) = '2013' AND Month(Atd_Datetime) = '6') A JOIN
Employee aa ON workid = aa.sn
GROUP BY WorkID, CONVERT(varchar, atd_datetime, 23), Employee_Name
HAVING datepart(hh, MAX(atd_datetime)) > 12
ORDER BY WorkID, atd_datetime DESC
select d.sn WorkID,d.atd_date+' '