Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
SQL






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
Posted

1 solution

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?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900