我需要 1 天的字符串值
“23:59:59”正在运行,但会导致延迟
“24:00:00”不起作用:将数据类型 varchar 转换为 datetime 时出错。
“1.00:00:00”不起作用:将数据类型 varchar 转换为 datetime 时出错。
这是我的代码:
PROCEDURE [dbo].[Procedure1]
@Start datetime,
@Finish datetime,
@TimeRange datetime
AS
BEGIN
SET NOCOUNT ON;
declare @TimeRanges as TABLE (SessionStart datetime, SessionEnd datetime);
with TimeRanges as (
select @Start as StartTime, @Start + @TimeRange as EndTime
union all
select StartTime + @TimeRange, EndTime + @TimeRange
from TimeRanges
where EndTime < @Finish )
select StartTime, EndTime, Count( Test.ScenarioID ) as TotalPeaks
from TimeRanges as TR left outer join
dbo.Test as Test on TR.StartTime <= Test.SessionStartTime and Test.SessionCloseTime < TR.EndTime
group by TR.StartTime, TR.EndTime
END