select
case
--shift I
when datepart(HH, [TimeStamp]) >= 5 and datepart(HH, [TimeStamp]) < 13 then
dateadd(HH, 5, dateadd(dd,0, datediff(dd,0,[TimeStamp])))
--shift II
when datepart(HH, [TimeStamp]) >= 13 and datepart(HH, [TimeStamp]) < 21 then
dateadd(HH, 13, dateadd(dd,0, datediff(dd,0,[TimeStamp])))
--shift III
when datepart(HH, [TimeStamp]) >= 21 then
dateadd(HH, 21, dateadd(dd,0, datediff(dd,0,[TimeStamp])))
when datepart(HH, [TimeStamp]) < 5 then
dateadd(HH, 21, dateadd(dd,0, datediff(dd,0,[TimeStamp])-1))
end as StartTime
from
Table1