-- QUERY TO DISPLAY ALL RULES WITH TARGET CLASSES AND THEIR OVERRIDE STATE (ANYWAY MORE THAN 1 OVERRIDE PER RULE) - (FILTERED ON 'ENU' AND 'FRA' LANGUAGES)
-- THE FINAL 'GROUP BY' CLAUSE IS TO DISPLAY ONLY ONE RULE OCCURENCE (WE ONLY WANT TO KNOW THAT RULE IS OVERRIDEN AT LEAST ONE TIME.
-- THAT IS EQUIVALENT TO DELETE THE 'ALL' STATEMENT IN UNION CLAUSE.
PRINT 'ALL RULES THAT IS OVERRIDEN AT LEAST 1 TIME OR NOT';
WITH TEMP1 (Rule_Name,Target_Class,Override_State)
AS
(
SELECT rv.DisplayName as Rule_Name
,MTV.DisplayName as Target_Class
,Override_State = CASE
WHEN mo.ParentId is null THEN 'NOT OVERRIDEN'
WHEN mo.ParentId is not null THEN 'OVERRIDEN'
END
FROM RuleView rv
FULL JOIN ModuleOverride mo on rv.Id = mo.ParentId
INNER JOIN [dbo].[ManagedTypeView] MTV on rv.TargetMonitoringClassId = MTV.Id
WHERE rv.Id not in (select mo.ParentId from ModuleOverride mo)
AND rv.LanguageCode in ('ENU','FRA')
AND MTV.LanguageCode in ('ENU','FRA')
UNION ALL
SELECT rv.DisplayName as Rule_name
,MTV.DisplayName as Target_Class
,Override_State = CASE
WHEN mo.ParentId is null THEN 'NOT OVERRIDEN'
WHEN mo.ParentId is not null THEN 'OVERRIDEN'
END
FROM RuleView rv
FULL JOIN ModuleOverride mo on rv.Id = mo.ParentId
JOIN [dbo].[ManagedTypeView] MTV on rv.TargetMonitoringClassId = MTV.Id
WHERE rv.Id in (select mo.ParentId from ModuleOverride mo)
AND rv.LanguageCode in ('ENU','FRA')
AND MTV.LanguageCode in ('ENU','FRA')
)
SELECT Rule_Name
,Target_Class
,Override_State
FROM TEMP1
GROUP BY Rule_Name,Target_Class,Override_State
ORDER BY Rule_Name