SCSM DW Query - Backlog
I am having a difficult time to figure out the backlog part.
The backlog must show all the incidents that were active at the end of that day.
I have this so far, but the figures are not the same as the ones manually recorded for the day and im not sure what else to try....
Select (CONVERT(date, CreatedDate)), count(CreatedDate) as [Created], count(IR3.ResolvedDate) as [Resolved],(Select count(ir.CreatedDate)from IncidentDimvw IR with(nolock)join IncidentTierQueuesvw IRSupport on IR.TierQueue_IncidentTierQueuesId=IRSupport.IncidentTierQueuesIdwhere ir.Status_IncidentStatusId in(2,5)and IRSupport.IncidentTierQueuesValue in(@Support)and ir.CreatedDate=( select max(CreatedDate) from IncidentDimvw IR2 with (nolock) where IR2.Id=IR.Id and convert(date,IR2.CreatedDate)<=convert(date,IR3.CreatedDate) ) )as [Backlog]from IncidentDimvw IR3 with (nolock)left join IncidentTierQueuesvw IRSupport on IR3.TierQueue_IncidentTierQueuesId=IRSupport.IncidentTierQueuesIdwhere CreatedDate between @StartDate and @EndDateand IRSupport.IncidentTierQueuesValue in (@Support)group by CONVERT(date, CreatedDate)order by CONVERT(date, CreatedDate)
Best Answer
-
Brian_Wiest Customer Super IT Monkey ✭✭✭✭✭With the help of my SQL engineer this will give you a base line. It runs against the datamart. You should be able to edit this to get your support group filter added to further drill down.declare @sdt datetime
set @sdt = '1 jan 2018'
declare @edt datetime
set @edt = '31 dec 2018'
;
with clean as (
select
cast(createddate as date) cd, -- Get rid of the time part so comparisons work right
cast(resolveddate as date) rd
from incidentdimvw
),
cre as (
select cd, count(*) ccnt -- Count the created tickets by day
from clean
group by cd
),
res as (
select rd, count(*) rcnt -- Count the resolved tickets by day
from clean
group by rd
),
dts as ( -- Create the complete list of days that had either a create or a resolve on them
select cd as dt
from cre
union
select rd
from res
),
together as ( -- Combine the two lists and...
select dt,
(select ccnt from cre where dts.dt = cre.cd) ccnt,
(select rcnt from res where dts.dt = res.rd) rcnt,
(select count(*) -- ...look back through the tickets and find the ones that are still open on any given day
from clean c
where cd <= dts.dt and (rd > dts.dt or rd is null)
) ocnt
from dts
)
select *
from together
where dt between @sdt and @edt -- Limit the report to the date range of interest
order by dt
6
Answers
set @sdt = '1 jan 2018'
declare @edt datetime
set @edt = '31 dec 2018'
;
with clean as (
select
cast(createddate as date) cd, -- Get rid of the time part so comparisons work right
cast(resolveddate as date) rd
from incidentdimvw
),
cre as (
select cd, count(*) ccnt -- Count the created tickets by day
from clean
group by cd
),
res as (
select rd, count(*) rcnt -- Count the resolved tickets by day
from clean
group by rd
),
dts as ( -- Create the complete list of days that had either a create or a resolve on them
select cd as dt
from cre
union
select rd
from res
),
together as ( -- Combine the two lists and...
select dt,
(select ccnt from cre where dts.dt = cre.cd) ccnt,
(select rcnt from res where dts.dt = res.rd) rcnt,
(select count(*) -- ...look back through the tickets and find the ones that are still open on any given day
from clean c
where cd <= dts.dt and (rd > dts.dt or rd is null)
) ocnt
from dts
)
select *
from together
where dt between @sdt and @edt -- Limit the report to the date range of interest
order by dt
Will give it a shot.
Thank you
G