CREATE OR ALTER PROCEDURE [dbo][schemma].[TrunkSummery]
@date datetime2(7),
-- @period int, -- TODO : set period via param = 30min, 1h etc.
AS
BEGIN
-- Creat timeslotable
with numbers(val) as
(select 1 union all select val + 1 from numbers where val < 48) --
TODO: Make 48 Parameterized
select @date, nbr.val,
dateadd(MINUTEminute, (nbr.val - 1) * 30, @date) as period_start,
dateadd(MINUTEminute, (nbr.val ) * 30, @date) as period_end
from numbers as nbr
order by nbr.val;
-- Itterate
with numbers(val) as
(select 1 union all select val + 1 from numbers where val < 48),
-- TODO: Make 48 Parameterized
periods as (
periods as ( select @date as [date], nbr.val,
dateadd(SECONDminute, (nbr.val - 1) * @period30, @date) as period_start,
dateadd(SECONDminute, (nbr.val ) * @period30, @date) as period_end
from numbers as nbr)
select /* src.Trunk */, select pers.period_start, @period as Period, src.RoutLabeltrunk, count(src.RoutLabeltrunk) as all,'all'
/*count*, count(MaxConnectionAtOncemaxAtOnce) as max */
--from periods as pers left join dbo.RAW_DATA@raw_data as src
from periods as pers inner join dboHDO.RAW_DATA as src
on src.StartDateTime >= pers.period_start and src.StartDateTime < pers.period_end
group by /*srcsrc.Trunk*/trunk, pers.period_start, pers.period_end, src.GatewayName
order by /*src.Trunk*/, pers.period_start, perssrc.period_endtrunk, src pers.GatewayName;period_end
END
GO
EXECUTE [dbo][schemma].[TrunkSummery] @date = '20210224', /*@period@period = 30*/ ;30;
GO