我最近似乎在这里问了很多问题,提前感谢任何帮助!
首先 - 我有一个日历表,可以使这更容易。日历表非常标准,日期ID,日期和该日期的不同格式。
我想给查询一个日期,并返回所有员工的列表以及他们是否在该日假期。
a discussion on the NiFi mailing list
LeaveTypeID为1表示假期2表示疾病,3表示同情,等等,此时我只关心假期。 StartDate和EndDate就像它们出现的那样 StartMidday是假日是否在第一天的中午开始(所以早上工作,午餐开始),同样的结束日,但在假期结束时)
理想情况下,如果可能的话,那天是否也是半天? 所以我希望我的结果是这样的(假设我选择了2016年11月4日的日期)
EmployeeID OnHoliday IsHalf
1 TRUE TRUE
2 FALSE FALSE
3 FALSE FALSE
4 FALSE FALSE
5 FALSE FALSE
希望这是足够的信息。提前再次感谢!
答案 0 :(得分:0)
我认为您可以在此之间使用:
declare @InputDate date='2016-09-16' --yur input date
select EmployeeId,
case when (select count(1) from EmployeeLeave
where (@InputDate between StartDate and EndDate)
and EmployeeLeave .EmployeeId=Employee .EmployeeId)>1 then 'True' else 'False' end as [OnHoliday],
case when ((select StartMidDay from EmployeeLeave
where (@InputDate between StartDate and EndDate)
and EmployeeLeave .EmployeeId=Employee .EmployeeId))=0.5 then 'True' else 'False' end as [IsHalf] ,
from Employee
答案 1 :(得分:0)
我想我可能已经找到了自己的解决方案
declare @DateAdd int=0 --add Days From Monday
declare @LeaveType int=1 -- Leave Type
declare @SelctedDate date = DATEADD(DD, @DateAdd, CAST('2016-11-21' AS DATE)) --Week Commencing
select
(CASE
WHEN (leaveTemp.StartMidday = '0.5' AND leaveTemp.StartDate = @SelctedDate) THEN '4:00'
WHEN (leaveTemp.EndMidday = '0.5' AND leaveTemp.EndDate = @SelctedDate) THEN '4:00'
WHEN LeaveID is not null THEN '8:00'
ELSE NULL
END ) as HolMon
from Employee left join
(select employeeID, LeaveID, StartDate, EndDate, StartMidday, EndMidday
from EmployeeLeave
where LeaveTypeID=@LeaveType and @SelctedDate between startdate and enddate
) as leaveTemp
on Employee.EmployeeID = leaveTemp.EmployeeID
ORDER BY Employee.EmployeeForename, Employee.EmployeeID
这似乎带回了我追求的目标,但这是最好的方法吗?