DECLARE @Count INT
SELECT @Count= COUNT(1) FROM DZ_TEMP.dbo.Temp_Five_Time_Interval_Source
BEGIN
IF @Count>0
TRUNCATE TABLE DZ_TEMP.dbo.Temp_Five_Time_Interval_Source
END
--插入数据
DECLARE @dayBegin datetime,@dayEnd datetime
set @dayBegin = '2020-07-25 00:00'
set @dayEnd = '2020-07-25 23:59'
while @dayBegin <=@dayEnd
begin
insert INTO DZ_TEMP.dbo.Temp_Five_Time_Interval_Source
select @dayBegin dayBegin ,dateadd(mi,30,@dayBegin) dayEnd --每30分钟一个间隔
SET @dayBegin=dateadd(mi,30,@dayBegin)
END