如何使用此代码更新出勤率

编程入门 行业动态 更新时间:2024-10-10 07:24:12
本文介绍了如何使用此代码更新出勤率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

声明@PDate datetime, @Hdate datetime, @In_Punch datetime, @Out_Punch datetime UPDATE MASTERPROCESSDAILYDATA SET状态=转换(时间,In_Punch)在'08:00'和'09:30'之间的情况和 转换(时间,Out_Punch)之间的情况'16:00'和'17:30'然后'P' 转换时的(时间,In_Punch)> '09:30'或转换(时间,In_Punch)< '09:30'AND转换(时间,Out_Punch)<> NULL或转换(time,Out_Punch)< = '15:30'或转换(time,In_Punch)< '09:30'AND转换(时间,Out_Punch)<> NULL或转换(time,Out_Punch)在'08:00'和'17:30'之间转换(time,In_Punch)= NULL或 转换(时间,In_Punch)在'08:00'之间和'17:30'并转换(时间,Out_Punch)= NULL然后'HL' 当(转换(时间,Out_Punch)在'08:00'之间时'17:30'并转换(时间,In_Punch)= NULL)或(转换(时间,In_Punch)在'08:00'和'17:30'之间转换(time,Out_Punch)= NULL)或转换(时间, Out_Punch)< = '15:30'然后'HL' 当Status ='WO'然后'WO' 当Status ='H'然后'H' 当Status ='MS'然后'HL' 转换时(时间,In_Punch)<> NULL和转换(time,Out_Punch)= NULL然后'HL' 转换时(时间,In_Punch)= NULL和转换(时间,Out_Punch)<> NULL然后'HL' - 当状态='A'和转换(时间,在'08:00'和'09:30'之间的In_Punch)和转换(时间,Out_Punch)= NULL然后'HL'< code>< pre>< pre lang =SQL> ;< big>< / big>< / pre>< / pre> 当In_Punch<>时, NULL和Out_Punch<> NULL和@PDate = @Hdate然后'HP' 转换(时间,In_Punch)在'08:00'和'17:30'之间转换(时间) ,Out_Punch)= NULL然后'HL' 当status ='WO'和In_Punch<> NUll AND Out_Punch<> NULL然后'WOP' 当In_Punch!= NUll AND Out_Punch!= NULL和@PDate = @Hdate然后'HP' b $ b else'A' end

当我尝试执行此代码时,状态不会更新时假期被分配,并且有拳头在那里。它显示状态为'P'但是,我想要'HP' 任何人都可以提供帮助我来解决这个问题。 谢谢

解决方案

猜猜,因为它有点难以阅读,但是对于所有这些案例陈述,只有一个可以提供答案而且它们不是相互排斥的 - 因此它在测试给出'HP'的条件之前达到提供'P'的条件br /> 所以将'when'案例移动到你实际需要测试它们的顺序 - 可能首先测试HP案例?

declare @PDate datetime, @Hdate datetime, @In_Punch datetime, @Out_Punch datetime UPDATE MASTERPROCESSDAILYDATA SET Status = case when convert(time,In_Punch) between '08:00'and '09:30' and convert(time,Out_Punch) between '16:00' and '17:30' then 'P' when convert(time,In_Punch) > '09:30' or convert(time,In_Punch) < '09:30' AND convert(time,Out_Punch) <> NULL or convert(time,Out_Punch) <= '15:30' or convert(time,In_Punch) < '09:30' AND convert(time,Out_Punch) <> NULL OR convert(time,Out_Punch) between '08:00' and '17:30' and convert(time,In_Punch) = NULL OR convert(time,In_Punch) between '08:00'and '17:30' and convert(time,Out_Punch) = NULL then 'HL' when (convert(time,Out_Punch) between '08:00' and '17:30' and convert(time,In_Punch) = NULL) OR (convert(time,In_Punch) between '08:00'and '17:30' and convert(time,Out_Punch) = NULL) OR convert(time,Out_Punch) <= '15:30' then 'HL' when Status = 'WO' then 'WO' when Status = 'H' then 'H' when Status = 'MS' then 'HL' when convert(time,In_Punch) <> NULL AND convert(time,Out_Punch) = NULL then 'HL' when convert(time,In_Punch) = NULL AND convert(time,Out_Punch) <> NULL then 'HL' --when Status = 'A' AND convert(time,In_Punch) between '08:00'and '09:30' and convert(time,Out_Punch) = NULL then 'HL'<code><pre><pre lang="SQL"><big></big></pre></pre> when In_Punch <> NULL AND Out_Punch <> NULL AND @PDate = @Hdate then 'HP' when convert(time,In_Punch) between '08:00'and '17:30' and convert(time,Out_Punch) = NULL then 'HL' when status = 'WO' And In_Punch <> NUll AND Out_Punch <> NULL then 'WOP' when In_Punch != NUll AND Out_Punch != NULL AND @PDate = @Hdate then 'HP' else'A' end

When i am trying to excecute this code thestatus is not updated when holiday is assigned and punches is there.It shows Status as 'P' but,i want 'HP' Can any one help me to solve this problem. Thanks

解决方案

Just guessing, as it's kinda hard to read , but with all those case statements, only one can supply an answer and they are not mutually exclusive - so it is hitting a condition that provides a 'P' before testing the condition that gives 'HP' So move your 'when' cases into the order you actually need to test them - probably testing the HP case first?

更多推荐

如何使用此代码更新出勤率

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

发布评论

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

>www.elefans.com

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