代码示例:
if datepart(hh,getdate())>8 or datepart(hh,getdate())<20
begin
;with rest1 as
(
select N=0,M=cast ('00:00' as varchar(5))
union all
select N=N+1,M=cast (right('0'+cast((N+1) as varchar(2)),2)+ ':00' as varchar(5)) from rest1 where N<23)
select * from rest1 where M between '08' and '20'
end
结果:
N M
8 08:00
9 09:00
10 10:00
11 11:00
12 12:00
13 13:00
14 14:00
15 15:00
16 16:00
17 17:00
18 18:00
19 19:00