得出一天的时间段记录。(如 1:00-2:00) if OBJECT_ID('fn_time') is not null drop function fn_time go create function fn_time (@n int)--每隔n小时一段 returns table as return( select 时间段=right(100+number*@n,2)+':00-'+right(100+(number+1)*@n,2)+':00' from master..spt_values where type='p' and number <= 23/@n and 24%@n=0 ) GO select * from fn_time(3) /* 时间段 00:00-03:00 03:00-06:00 06:00-09:00 09:00-12:00 12:00-15:00 15:00-18:00 18:00-21:00 21:00-24:00 */