I am trying to put together the query for a multiple row report. I have this working. Each type is coming from a different database, so I am using subqueries to pull it together and the results are accurate, but all on one row. I would like to put incidents on their own row, service requests on their own row, and there are four other tables I want to pull the same aged data from. How do I get each set of aged days onto their own row for each type of ticket?
--SELECT COUNT (*)
Select ai15 as [Incidents Aged 15 Days], as15 as [Service Requests Aged 15 Days],
ai30 as [Incidents Aged 30 Days], as30 as [Service Requests Aged 30 Days],
ai60 as [Incidents Aged 60 Days], as60 as [Service Requests Aged 60 Days],
ai90 as [Incidents Aged 90 Days], as90 as [Service Requests Aged 90 Days],
ai120 as [Incidents Aged 120 Days], as120 as [Service Requests Aged 120 Days]
from
(select count(*) as ai15
from Incidents
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 15
) gt15i,
(select count(*) as ai30
from Incidents
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 30
) gt30i,
(select count(*) as ai60
from IncidentDimVw
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 60
) gt60i,
(select count(*) as ai90
from Incidents
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 90
) gt90i,
(select count(*) as ai120
from Incidents
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 120
) gt120i,
(select count(*) as as15
from SRs
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 15
) gt15s,
(select count(*) as as30
from SRs
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 30
) gt30s,
(select count(*) as as60
from ServiceRequestDimVw
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 60
) gt60s,
(select count(*) as as90
from SRs
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 90
) gt90s,
(select count(*) as as120
from SRs
where status like '%Active%' and ABS(DATEDIFF(day, CreatedDate, GETDATE())) > 120
) gt120s