Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使SQL能够在数周内工作_Sql Server - Fatal编程技术网

Sql server 使SQL能够在数周内工作

Sql server 使SQL能够在数周内工作,sql-server,Sql Server,我有一份报告,确定某一周在时间表上输入少于40小时的员工: With Under40s as ( Select Distinct Entry.UUID, Entry.FirstName, Entry.LastName, Team.PersonUnit, Team.TeamName From Entry as Entry Inner Join TeamOrganization as Team on Team.PersonUUID = Entry.UUID and @EnteredDate

我有一份报告,确定某一周在时间表上输入少于40小时的员工:

With Under40s as (
Select Distinct Entry.UUID, Entry.FirstName, Entry.LastName, Team.PersonUnit, Team.TeamName
From Entry as Entry
Inner Join TeamOrganization as Team on Team.PersonUUID = Entry.UUID and @EnteredDate     between Team.PeriodBeginDate and Team.PeriodEndDate
Where 
(
    Select sum(Entry2.Hours) From Entry as Entry2
    Where Entry2.UUID = Entry.UUID and Entry2.Date Between @StartDate and @EndDate
) < 40
Or not exists 
(
    Select 1 From Entry as Entry2
    Where Entry2.UUID = Entry.UUID and Entry2.Date Between @StartDate and @EndDate
)
)
Select distinct Under40s.UUID, Under40s.FirstName, Under40s.LastName, Under40s.PersonUnit, Under40s.TeamName, Case
    When Sum(Entry.Hours) is null then 0
    Else Sum(Entry.Hours)
    End as TotalHours 
From Under40s
Left Join Entry as Entry on Entry.UUID = Under40s.UUID and Entry.Date Between @StartDate and @EndDate
Where Under40s.PersonUnit in (@PersonUnit) and Under40s.TeamName in (@Teams)
Group By Under40s.UUID, Under40s.FirstName, Under40s.LastName, Under40s.PersonUnit, Under40s.TeamName
Order By Under40s.LastName, Under40s.FirstName
客户现在希望能够输入一周以上的日期范围。我想他们希望每周都能看到在这个日期范围内,谁的报告时间少于40小时。我不确定如何或是否可以修改SQL以交付这样的报告。谁能给我一个提示吗


谢谢

假设每个工作日为8小时,一种选择是获取开始日期和结束日期之间的日差,然后将其乘以8,并使用产品作为标准。例如:startdate:20/11/2013和enddate:31/12/2013是41天,包括周末,因此您还必须筛选周末或非工作日,但就像示例41*8=328一样。因此,不是少于40,而是少于328。这里有一个链接指向排除周末和其他指定日期的工作解决方案:

您是否使用reporting services显示此cte的输出?@SelectDistinct:是的。我想他们真正想要的是:在2013年10月28日至2013年11月17日期间,员工1在第1周报告了20个小时,员工2在第2周报告了35小时,员工3在第1周报告了15小时,在第2周报告了29小时。我只是不知道该怎么做。我甚至不确定这是否真的可能。啊,我知道这是否是他们想要的,然后我想他可以得到几周,然后是每周的开始和结束日期等等。你会如何使用直接SQL来做到这一点?