SELECT
'===INFO=> '
,SUBSTR(INSTANCENAME,1,8) AS INSTANCENAME
,SUBSTR(DBNAME,1,8) AS DBNAME
,LEVEL
,SUBSTR(IMPACT,1,10) AS IMPACT
,MIN(HIST.TIMESTAMP) AS FIRST_OCCUR
,MAX(HIST.TIMESTAMP) AS LAST_OCCUR
,COUNT(*) AS COUNT
,CASE
WHEN LENGTH(MAX(VARCHAR(MSG))) > 407 THEN
X'0A' || '====MSG=> ' || SUBSTR(rtrim(REPLACE(MAX(VARCHAR(MSG)),X'0A',' ')),1,150) || ' (...) ' || SUBSTR(RIGHT(REPLACE(MAX(VARCHAR(MSG)),X'0A',' '),150),1,250)
ELSE
X'0A' || '====MSG=> ' || SUBSTR(rtrim(REPLACE(MAX(VARCHAR(MSG)),X'0A',' ')),1,407)
END AS MSG_LIKE
FROM TABLE(PD_GET_DIAG_HIST('MAIN', CAST(NULL AS CHAR(1)), CAST(NULL AS CHAR(1)), CURRENT TIMESTAMP - 7 DAYS, CAST(NULL AS TIMESTAMP))) as HIST
WHERE (LEVEL IN ('C','E','S','W') OR IMPACT IN ('CRITICAL','IMMEDIATE','POTENTIAL')) and MSG is not NULL
GROUP BY INSTANCENAME, DBNAME, LEVEL, IMPACT, SUBSTR(SUBSTR(VARCHAR(LEFT(MSG,150)),1, LOCATE(' ',VARCHAR(LEFT(MSG,150))) -1),1,70)
ORDER BY 7 DESC, INSTANCENAME, DBNAME
SELECT
'===INFO=> '
,MEMBER
,SUBSTR(INSTANCENAME,1,8) AS INSTANCENAME
,SUBSTR(DBNAME,1,8) AS DBNAME
,LEVEL
,SUBSTR(IMPACT,1,10) AS IMPACT
,MIN(HIST.TIMESTAMP) AS FIRST_OCCUR
,MAX(HIST.TIMESTAMP) AS LAST_OCCUR
,COUNT(*) AS COUNT
,CASE
WHEN LENGTH(MAX(VARCHAR(MSG))) > 407 THEN
X'0A' || '====MSG=> ' || SUBSTR(rtrim(REPLACE(MAX(VARCHAR(MSG)),X'0A',' ')),1,150) || ' (...) ' || SUBSTR(RIGHT(REPLACE(MAX(VARCHAR(MSG)),X'0A',' '),150),1,250)
ELSE
X'0A' || '====MSG=> ' || SUBSTR(rtrim(REPLACE(MAX(VARCHAR(MSG)),X'0A',' ')),1,407)
END AS MSG_LIKE
FROM TABLE(PD_GET_DIAG_HIST('MAIN', NULL, NULL, CURRENT TIMESTAMP - 7 DAYS, NULL, -2)) as HIST
WHERE (LEVEL IN ('C','E','S','W') OR IMPACT IN ('CRITICAL','IMMEDIATE','POTENTIAL')) and MSG is not NULL
GROUP BY INSTANCENAME, DBNAME, MEMBER, LEVEL, IMPACT, SUBSTR(SUBSTR(VARCHAR(LEFT(MSG,150)),1, LOCATE(' ',VARCHAR(LEFT(MSG,150))) -1),1,70)
ORDER BY 7 DESC, INSTANCENAME, DBNAME, MEMBER