如何根据定义的表和数据检索当前班次记录,getdate()以及哪个位于现有ShiftStartTime和ShiftEndTime根据定义的表和数据之间?
如果时间到了 12:00 AM 可以换班吗?
创建表 ShiftMaster ( ShiftID 字符(4), ShiftName 字符(7), ShiftDescripton varchar(20), ShiftStartTime 时间, ShiftEndTime 时间 )
插入到 ShiftMaster
价值观
('SHF1', 'Shift A', 'First Shift', '07:15:01', '15:45:00'),
('SHF2', 'Shift B', '二班', '15:45:01', '00:15:00'),
('SHF3', 'Shift C', '三班', '00:15:01', '07:15:00')
SELECT * FROM VHASM2.ShiftMaster
WHERE FORMAT(getdate(),'HH:mm:ss') between ShiftStartTime and ShiftEndTime;
Run Code Online (Sandbox Code Playgroud)
select *
from ShiftMaster
where
'' + cast(datepart(hh, getdate()) as char(2)) + ':' + cast(datepart(n, getdate()) …Run Code Online (Sandbox Code Playgroud) sql-server ×1