我正在尝试在我们的门系统数据库上运行 SQL 查询,以查看每个人什么时候开始工作。目前我只是在使用语句
Where DATEPART(hh, ev.dEvent_Date) between '5' and '10'
将结果限制在上午 5 点到 10 点之间,但 John Smith 可能已经到外面去接东西或休息一下,因此报告将在一天内为一个人提供多个条目。有没有一种方法可以让我每天为每个人安排第一个活动?我当前的查询如下
Select tFirstName as FirstName
,tLastName as LastName
,DATENAME(dw, ev.dEvent_Date) as [Day]
,CONVERT(varChar(11),ev.dEvent_Date) as [Date]
,CONVERT(varchar(2) ,DatePart(hh,devent_Date))+':'+ case when len(convert(varchar(5),DatePart(n,devent_Date))) = '1' then '0'+ convert(varchar(5),DatePart(n,devent_Date))else convert(varchar(5),DatePart(n,devent_Date)) end as [Time]
From dbo.tblevents as ev, dbo.tblEmployees as em
Where DATEPART(hh, ev.dEvent_Date) between '5' and '10'
AND ev.dEvent_Date between DATEADD(dd, -(DATEPART(dw, DATEADD(ww, -1, getdate()))-1), DATEADD(ww, -1, getdate())) and DATEADD(dd, 7-(DATEPART(dw, DATEADD(ww, -1, getdate()))), DATEADD(ww, -1, getdate()))
And em.iEmployeeNum = ev.iUserNum
AND tByte6 = 11
AND tByte8 = 22
Order by LastName, [Date]