DECLARE @BTime DATETIME,@ETime DATETIME;DECLARE @Temp TABLE (ID BIGINT IDENTITY(1,1),aid BIGINT,newcode BIGINT,btime DATETIME,etime DATETIME);DECLARE @Temp2 TABLE (aid BIGINT,newcode BIGINT,dayTime VARCHAR(100));INSERT INTO @Temp SELECT [id] ,[newCod…