如何在没有日志表的日子里缺席?

编程入门 行业动态 更新时间:2024-10-11 13:30:28
本文介绍了如何在没有日志表的日子里缺席?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要在#dates表中缺席,如果日期不在日志表中 任何帮助将不胜感激 我尝试过:

Declatr @ DateT 表(D 日期); 选择 @ d1 = ' 10/1/2013',@ d2 = ' 2013年10月31日; ; 日期( date ) as ( 选择 @ d1 union 所有 选择 dateadd(d, 1 , date ) 来自日期 其中 日期< @ d2 ) 插入 进入 @ DateT 选择 日期 as CountedDays 来自日期; 选择 不同 ID,转换( time ,Log_D),Late,EarlyOut,AbsentOne,Day(Log_D) as day1 From ( SELECT m.ID,L.Log_D,LC,T.EnterAllow_FD,W.FirstStartTime, T.Late_FD,T.EarlyOut_FD,T.OutAllow_FD,W.FirstEndTime,a.StartDate,a.EndDate,W.id WID, ( CASE WHEN convert ( time , L.Log_D)> Dateadd(mi,T.Late_FD,W.FirstStartTime)和 convert ( time ,L.Log_D)< Dateadd(mi,T.EnterAllow_FD + T.Late_FD,W.FirstStartTime)和 COUNT(*) OVER ( PARTITION BY L.EmpId,day(L.Log_D))= 2 和 LC = 1 然后 ' Ê' end ) as 晚了,( CASE WHEN convert ( time ,L.Log_D)< Dateadd(mi,-T.EarlyOut_FD,W.FirstEndTime)和 convert ( time ,L.Log_D)> Dateadd(mi, - (T。 EarlyOut_FD + T.OutAllow_FD),W.FirstEndTime)和 COUNT(*) OVER ( PARTITION BY L.EmpId,day(L.Log_D))= 2 和 LC = 2 然后 ' خ,م' end ) as EarlyOut, ( CASE WHEN (COUNT(*) OVER ( PARTITION BY L.EmpId,day (L.Log_D))< 2 ) 或( convert ( time ,L.Log_D)> Dateadd(mi,T.EnterAllow_FD + T.Late_FD,W.FirstStartTime) 和 convert ( time ,L.Log_D)< Dateadd(mi , - (T.EarlyOut_FD + T.OutAllow_FD),W.FirstEndTime))那么 ' غ' END ) as [AbsentOne] 来自 WorkPeriod W,LogT L 完整 加入 MinimumInfoT m m.ID = L.EmpId,TimeRulesT T,WorkPeriod a2 join WorkPeriod a on a2.id = a.PeridNo 其中​​月(L.Log_D)= 10 和年(L.Log_D)= 2013 和 LC ( 1 , 2 ) 和 L.Log_D 不 a.StartDate 和 a.EndDate 和 M.ID = L.EmpId 和 W.id = m.W_Period 和 W.id = T.WorkPeriodID 和 W.id = a.PeridNo) as tt, @ DateT T2 order by ID,day1

解决方案

最简单的方法是使用JOIN来连接f过滤数据。 我不打算通过你的代码试图找出你的表模式,所以我创建了一组虚拟表来证明这一点:

创建 表员工(EmpId int 身份( 1 , 1 ),Name nvarchar ( 125 )) 将 插入员工值(' Joe Bloggs') 创建 表 attendanceLog ( id int identity ( 1 , 1 ), EmpId int , DateLogged 日期 ) 插入 进入 attendanceLog 值 ( 1 ,' 2013-10- 02'),( 1 ,' 2013-10-03'),( 1 ,' 2013-10-04'),( 1 ,' 2013-10-05'),( 1 ,' 2013-10-06'),( 1 ,' 2013-10-07'),( 1 ,' 2013-10-08' )

以下查询将列出(您的)@DateT表中未出现在(my)AttendanceLog表中的日期:

选择 D 来自 @ DateT D left 外部 JOIN attendanceLog AL ON AL.DateLogged = DD WHERE EmpId IS NULL

注意我使用了日期列类型。您似乎在代码中使用了大量 CONVERT 函数,因此您可能需要将 ON 子句更改为 ON CAST(AL.DateLogged AS 日期)= DD

使用此代码

SELECT DATENAME(dw,GETDATE()) union all SELECT DATENAME(dw,DATEADD(dd, 1 ,GETDATE())) union 全部 SELECT DATENAME(dw,DATEADD(dd, 2 ,GETDATE())) union all SELECT DATENAME(dw,DATEADD(dd, 3 ,GETDATE())) union 全部 SELECT DATENAME(dw,DATEADD(dd, 4 ,GETDATE())) union all SELECT DATENAME(dw) ,DATEADD(dd, 5 ,GETDATE())) union 全部 SELECT DATENAME(dw,DATEADD(dd, 6 ,GETDATE ()))

I need to get absent days from #dates table if the days not in log table any help will be appreciated What I have tried:

Declatr @DateT Table(D Date); select @d1 = '10/1/2013',@d2= '10/31/2013'; ;with dates ( date ) as ( select @d1 union all select dateadd(d,1,date) from dates where date < @d2 ) insert into @DateT select date as CountedDays from dates ; Select distinct ID,convert(time,Log_D),Late,EarlyOut,AbsentOne,Day(Log_D) as day1 From(SELECT m.ID,L.Log_D,L.C,T.EnterAllow_FD,W.FirstStartTime,T.Late_FD,T.EarlyOut_FD,T.OutAllow_FD,W.FirstEndTime,a.StartDate,a.EndDate,W.id WID, (CASE WHEN convert(time,L.Log_D)>Dateadd(mi,T.Late_FD,W.FirstStartTime) and convert(time,L.Log_D)<Dateadd(mi,T.EnterAllow_FD+T.Late_FD,W.FirstStartTime) and COUNT(*) OVER (PARTITION BY L.EmpId,day(L.Log_D)) = 2 and L.C =1 then 'ت'end )as Late, (CASE WHEN convert(time,L.Log_D)<Dateadd(mi,-T.EarlyOut_FD,W.FirstEndTime) and convert(time,L.Log_D)>Dateadd(mi,-(T.EarlyOut_FD+T.OutAllow_FD),W.FirstEndTime)and COUNT(*) OVER (PARTITION BY L.EmpId,day(L.Log_D)) = 2 and L.C =2 then 'خ,م'end )as EarlyOut, (CASE WHEN (COUNT(*) OVER (PARTITION BY L.EmpId,day(L.Log_D)) < 2) or (convert(time,L.Log_D)>Dateadd(mi,T.EnterAllow_FD+T.Late_FD,W.FirstStartTime ) and convert(time,L.Log_D)<Dateadd(mi,-(T.EarlyOut_FD+T.OutAllow_FD),W.FirstEndTime)) THEN 'غ' END) as [AbsentOne] from WorkPeriod W,LogT L full join MinimumInfoT m on m.ID =L.EmpId ,TimeRulesT T,WorkPeriod a2 join WorkPeriod a on a2.id=a.PeridNo where month(L.Log_D) =10 and year(L.Log_D) =2013 and L.C in(1,2) and L.Log_D not Between a.StartDate and a.EndDate and M.ID =L.EmpId and W.id =m.W_Period and W.id=T.WorkPeriodID and W.id=a.PeridNo) as tt,@DateT T2 order by ID,day1

解决方案

The easiest way to do this is to use a JOIN to filter the data. I wasn't going to wade through your code to try and work out your table schemas so I created a dummy set of tables to demonstrate the point :

create table Employee (EmpId int identity(1,1), Name nvarchar(125)) insert into Employee values ('Joe Bloggs') Create Table attendanceLog ( id int identity(1,1), EmpId int, DateLogged Date ) insert into attendanceLog values (1, '2013-10-02'), (1, '2013-10-03'), (1, '2013-10-04'), (1, '2013-10-05'), (1, '2013-10-06'), (1, '2013-10-07'), (1, '2013-10-08')

The following query will then list the dates from (your) @DateT table that do not appear in (my) AttendanceLog table:

select D from @DateT D left outer JOIN attendanceLog AL ON AL.DateLogged=D.D WHERE EmpId IS NULL

Note I have used a Date column type. You appear to be using a lot of CONVERT functions in your code so you may need to change the ON clause to

ON CAST(AL.DateLogged AS Date)=D.D

use this code

SELECT DATENAME(dw, GETDATE()) union all SELECT DATENAME(dw, DATEADD(dd, 1, GETDATE())) union all SELECT DATENAME(dw, DATEADD(dd, 2, GETDATE())) union all SELECT DATENAME(dw, DATEADD(dd, 3, GETDATE())) union all SELECT DATENAME(dw, DATEADD(dd, 4, GETDATE())) union all SELECT DATENAME(dw, DATEADD(dd, 5, GETDATE())) union all SELECT DATENAME(dw, DATEADD(dd, 6, GETDATE()))

更多推荐

如何在没有日志表的日子里缺席?

本文发布于:2023-10-27 04:18:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532286.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日子里   如何在   日志

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!