日期:2014-05-18 浏览次数:20614 次
IF EXISTS (SELECT 1 FROM SYSOBJECTS WHERE name = 'tba') BEGIN DROP TABLE tba END GO CREATE TABLE tba ( StartTime VARCHAR(7), EndTime VARCHAR(7) ) GO INSERT INTO tba SELECT '08:20','16:00' UNION SELECT '16:01','20:00' UNION SELECT '20:01','4:0' GO DECLARE @Current VARCHAR(7) SET @Current = '21:00' SELECT * FROM tba WHERE @Current BETWEEN StartTime AND CASE WHEN LEFT(EndTime,CHARINDEX(':',EndTime) - 1) < LEFT(StartTime,CHARINDEX(':',StartTime) - 1) THEN RTRIM(CAST(LEFT(EndTime,CHARINDEX(':',EndTime) - 1) AS INT) + 24) + RIGHT(EndTime,CHARINDEX(':',EndTime)) ELSE EndTime END StartTime EndTime 20:01 4:0