WITH VALID_PSQL (
PSQL_TYPE,
ROUTE_NAME,
VALID)
AS (SELECT
'Procedure',
RDB$PROCEDURE_NAME,
RDB$VALID_BLR
FROM
RDB$PROCEDURES
WHERE
RDB$PROCEDURES.RDB$PACKAGE_NAME IS NULL
UNION ALL
SELECT
'Function',
RDB$FUNCTION_NAME,
RDB$VALID_BLR
FROM
RDB$FUNCTIONS
WHERE
RDB$FUNCTIONS.RDB$PACKAGE_NAME IS NULL
UNION ALL
SELECT
'Package',
RDB$PACKAGE_NAME,
RDB$VALID_BODY_FLAG
FROM
RDB$PACKAGES
UNION ALL
SELECT
'Trigger',
RDB$TRIGGER_NAME,
RDB$VALID_BLR
FROM
RDB$TRIGGERS
WHERE
RDB$TRIGGERS.RDB$SYSTEM_FLAG = 0)
SELECT
PSQL_TYPE,
ROUTE_NAME,
VALID
FROM
VALID_PSQL
WHERE
EXISTS(SELECT
*
FROM
RDB$DEPENDENCIES
WHERE
RDB$DEPENDENT_NAME = VALID_PSQL.ROUTE_NAME
AND RDB$DEPENDED_ON_NAME = 'MYDOMAIN');