我正在从文本(.txt)文件将数据导入数据库表中。由于该文本文件仅包含出勤数据,例如如果某人当天出席或将其ID卡交换到出勤设备,则仅会保存当天的数据。 现在,我尝试以某种方式导出/表示数据,如果有人不显示其数据,则查询必须返回所有值,应显示为“他的ID和出勤日将显示,但出入时间为零或空值”
我已经尝试了UNION / UNION ALL和JOIN,但结果与我的期望不符。
我得到的结果:-
我期望的结果:-
AttendDate | Emplid | EmplName | OutTime | InTime
2019-06-27 | SAO-21-001| Suman Mondol| 14:53:47 |13:28:34
2019-06-27 | SAO-21-001| Suman Mondol| 00:00:00 |00:00:00
2019-06-29 | SAO-21-001| Suman Mondol| 13:17:12 |9:08:48
我已经尝试了以下查询:
Select distinct c.Date as Attendate
,t.EmplId
,t.Name
,t.AttendTimeMax
,t.AttendTimeMin
from AccessAttenHO t Right Outer JOin dbo.HRCalendar c on t.AttendDate=c.Date
where c.Date between '2019-06-01' and '2019-06-30'
order by t.EmplId;
和主表“ AccessAttenHO ”填充数据,如下所示:
Insert into AccessAttenHO(EmplId,Name,AttendDate,AttendTimeMax,AttendTimeMin, IsLate,UserId,TranDate,BranId,AttendType,DeptId)
select HREmployee.emplid,
HREmployee.EmplFirstName,
TempAttendImport.AttendDate,
MAX(CAST(TempAttendImport.AttendTime as time))maxtime,
MIN(CAST(TempAttendImport.AttendTime as time))mintime,
(case
when HREmployee.AttendType='General' and (MIN(cast(AttendTime as time))) >=CAST('09:16:00' AS time)
THEN 'T'
ELSE 'F'
END) ISLATE , TempAttendImport.UserId,TempAttendImport.TrnsDate,HREmployee.BranId,HREmployee.AttendType,HREmployee.DeptId
from TempAttendImport, HREmployee
where TempAttendImport.EmplId =HREmployee.IDCARDNO
group by HREmployee.emplid,TempAttendImport.AttendDate,HREmployee.EmplFirstName, HREmployee.AttendType,TempAttendImport.UserId,TempAttendImport.TrnsDate,HREmployee.BranId,HREmployee.AttendType,HREmployee.DeptId
ORDER BY HREmployee.emplid