-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathService Instances.sql
More file actions
59 lines (51 loc) · 2 KB
/
Service Instances.sql
File metadata and controls
59 lines (51 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Returns the URLs of all active Service Instances that have no CIs associated.
DECLARE @BaseUrl VARCHAR(100) = 'https://4me-demo.com' -- Use your base URL here
DECLARE @Account VARCHAR(100) = 'wdc' -- Optionally used below
SELECT SI.Name
,concat(@BaseUrl + '/service_instances/', SI.[ITRP ID]) url
FROM dbo.ALL_service_instances_Normalized SI
LEFT JOIN dbo.ALL_cis_Service_Instances CI_SI
ON SI.Name = CI_SI.Service_Instance AND SI.ACCOUNT = CI_SI.Service_Instance_Account
WHERE SI.Status ='in_production' -- and SI.ACCOUNT = @Account
GROUP BY SI.[ITRP ID], SI.Name
HAVING count(CI_SI.[ITRP ID]) = 0
ORDER BY SI.[ITRP ID]
;
-- Returns the URLs of all active Service Instances that have only inactive CIs
-- or no CIs at all associated.
DECLARE @BaseUrl VARCHAR(100) = 'https://4me-demo.com' -- Use your base URL here
SELECT url FROM
(
SELECT
ALL_service_instances_Normalized."ITRP ID",
CONCAT(@BaseUrl + '/service_instances/', ALL_service_instances_Normalized."ITRP ID") url,
COUNT (CASE WHEN all_cis_normalized.status in
(
-- 'archived',
-- 'being_built',
-- 'being_tested',
-- 'broken_down',
'in_production',
-- 'in_stock',
-- 'in_transit',
'installed',
-- 'lent_out',
-- 'lost_or_stolen',
-- 'ordered',
-- 'removed',
-- 'reserved',
-- 'standby_for_continuity',
-- 'to_be_removed',
'undergoing_maintenance'
) THEN 1 ELSE NULL END) as active_cis
FROM ALL_service_instances_Normalized
JOIN ALL_cis_Service_Instances
on ALL_cis_Service_Instances.account = ALL_service_instances_Normalized.account and ALL_cis_Service_Instances.service_instance = ALL_service_instances_Normalized.name
JOIN all_cis_normalized
on all_cis_normalized."ITRP ID" = ALL_cis_Service_Instances."ITRP ID"
WHERE ALL_service_instances_Normalized.Status IN ('in_production') -- Only active SIs
GROUP BY ALL_service_instances_Normalized."ITRP ID"
) t
WHERE active_cis = 0
ORDER BY "ITRP ID"
;