How do i program a column to show a shift based on the time value od a date field ie if the time portion(HH:MM) of the date time field is between 07:30 and 16:30 then 'Day shift' if between 16:30 and 23:30 then 'Eveneing Shift' etc.
select
case
when (datepart(hh,@r) <= 16 and datepart(mm,@r) <= 30 and datepart(hh,@r) >= 7 and datepart(mm,@r) >= 30) then 'Day Shift'
else 'Evening Shift'
end
you can substitute the @r variable with your datetimefield, and include more criteria if you have more than one category.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.