Table T1
Start time End time
09:00:00-12:00:00
14:00:00-17:00:00
Query whether the current server time is within the table T1 time period, if any, select the
The selected SQL result set is as follows, SQL, note: SQL2000 environment
Start time End time
14:00:00-17:00:00
Method One:
DECLARE
@t
TABLE
(
beginTime
CHAR
(8),
endTime
CHAR
(8)
)
INSERT
INTO
@t
values
(
‘09:00:00‘
,
‘12:00:00‘
)
INSERT
INTO
@t
values
(
‘14:00:00‘
,
‘17:00:00‘
)
SELECT
*
FROM
@t
WHERE
CONVERT
(
CHAR
(8), GETDATE(),114)
BETWEEN
beginTime
AND
endTime
/*
beginTime endTime
14:00:00 17:00:00
*/
Method Two: IF object_id (' tempdb. #T1 ') is not a NULL DROP TABLE #T1
CREATE TABLE #T1 (id INT IDENTITY, start time NVARCHAR (50), End time NVARCHAR (50))
INSERT into #T1
(Start time, end time)
VALUES (' 09:00:00 ', ' 12:00:00 ')
INSERT into #T1
(Start time, end time)
VALUES (' 14:00:00 ', ' 17:00:00 ')
SELECT * from #T1 WHERE
Convert (datetime, ' 1900-01-01 ' + start Time) <=convert (datetime, ' 1900-01-01 ' +substring (CONVERT (NVARCHAR), GETDATE () , 21), 12,50))
and
Convert (datetime, ' 1900-01-01 ' + End time) >=convert (datetime, ' 1900-01-01 ' +substring (CONVERT (NVARCHAR), GETDATE () , 21), 12,50))
SQL queries whether the current server time is within the table T1 time period, and if so, select the