Better to compare datetimes than to compare strings.
case when convert(datetime,a.timein,
Having said that, you have a different problem if the office time is before midnight and the time in is after midnight.
Main Topics
Browse All TopicsSQL Server 2005
If a person has come (timein varchar(8) ) 180 minutes late then his office time (otimein)
he should be treated as 1 day absent.
If he is 77 minutes late, he should be treated as 1/2 absent.
If he is 17 minutes late, he should be treated as 1/4 absent.
My code, (see code snippet) works as long as the otimein is less than 21:00:00,
otherwise it fails because then the dateadd functions makes it to next day.
What is the correct way?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi dqmg,
Could you recode my this try in more efficient way.
update a
set remarks = case when a.flag not in ('R','G') then
case when datediff(s,convert(datetim
else case when datediff(s,convert(datetim
else case when datediff(s,convert(datetim
else a.remarks
end end end end
from @t a
>>My second try is also not working correctly.
ofcourse it will not give your desired result. the only thing can solve your problem is that there should be date part in the fields not as you are concatenating.
>>Could you recode my this try in more efficient way.
no need to concate date with time convert(datetime,'1969/01/
just use convert(datetime, a.timein) it will automatically add default date with your time like
like if i use
select convert(datetime,'9:10') It will be '1900-01-01 09:10:00.000'
have following query but again i say that it will not solve your problem.
One thing that you can do... set some time period say('00:00' and '3:00') ... if timein is between that period than consider is as the previous day's timein. I can explain this if you require this way
Regards,
Kashif
Business Accounts
Answer for Membership
by: MuhammadKashifPosted on 2009-11-06 at 22:28:37ID: 25765198
For this your Times (timein, otimein) should contain date part too. like '2009/11/07 09:00'
bit change in your query because no need to use convert.
try following
Regards,
Kashif
Select allOpen in new window