我同意Keith的说法,最好在应用程序中完成此 *** 作。服务器和交叉连接到查找表对于大型源表而言将变得昂贵,但是出于娱乐目的,我整理了一个快速示例。
declare @QuarterHours table ( QuarterHour time ) declare @x time set @x = '00:00' insert into @QuarterHours (QuarterHour) values (@x) set @x = DATEADD(minute, 15, @x) while @x <> '00:00' begin insert into @QuarterHours (QuarterHour) values (@x) set @x = DATEADD(minute, 15, @x) end declare @test table ( id int, starttime datetime, endtime datetime ) insert into @test (id, starttime, endtime) values (1, '2010-01-01 08:28', '2010-01-01 08:47') select t.id, q.QuarterHour from @test t cross join @QuarterHours q where q.QuarterHour between cast(t.starttime as time) and cast(t.endtime as time)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)