From 8fbb58063a14ce13d9f741f18a326e218a6ade2a Mon Sep 17 00:00:00 2001 From: Blake Drumm Date: Thu, 14 Jul 2022 10:04:32 -0400 Subject: [PATCH] Create Gather-sys.messages-SCOM.sql --- SQL Queries/Gather-sys.messages-SCOM.sql | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 SQL Queries/Gather-sys.messages-SCOM.sql diff --git a/SQL Queries/Gather-sys.messages-SCOM.sql b/SQL Queries/Gather-sys.messages-SCOM.sql new file mode 100644 index 0000000..2fd8d62 --- /dev/null +++ b/SQL Queries/Gather-sys.messages-SCOM.sql @@ -0,0 +1,31 @@ +#Original Author: Benign Sage +#Original Location: https://github.com/benignsage/sqlserver-sys.messages-scom/blob/master/script1.sql +#Original Post: https://www.sqlalliance.com/viewtopic.php?f=8&t=3 +SELECT +m.message_id, +m.language_id, +l.name, +m.severity, +m.is_event_logged, +m.text, +'EXEC sp_addmessage @msgnum = ' + CONVERT(VARCHAR, m.message_id) + ', @msgtext = N''' + REPLACE(m.text, '''', '''''') ++ ''', @severity = ' + CONVERT(VARCHAR, m.severity) + ', @lang = ''' + l.name + ''', @with_log = ' + +( + SELECT + CASE is_event_logged + WHEN 1 THEN + 'True' + ELSE + 'False' + END + FROM + sys.syslanguages + WHERE + lcid = m.language_id +) + ', @replace = ''REPLACE''' AS SQLCommand +FROM +sys.messages AS m +INNER JOIN sys.syslanguages AS l +ON m.language_id = l.lcid +WHERE +message_id >= 777000000