From 726294cfe95fa858e4c34a333b83bc6238cb2c26 Mon Sep 17 00:00:00 2001 From: Erik Darling <2136037+erikdarlingdata@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:20:06 -0400 Subject: [PATCH] Fix trigger name extraction when comment contains ' ON ' (#666) CHARINDEX(N' ON ', st.text) searched from the start of the text, so a comment like "Update Current LoadIndex Id on Machine record" before CREATE TRIGGER would match first, producing a negative SUBSTRING length. Now passes the start position after CREATE TRIGGER as the third argument to CHARINDEX so it only finds the ON clause after the trigger name. Co-Authored-By: Claude Opus 4.6 (1M context) --- Lite/Services/RemoteCollectorService.ProcedureStats.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lite/Services/RemoteCollectorService.ProcedureStats.cs b/Lite/Services/RemoteCollectorService.ProcedureStats.cs index 2b541c50..58a50570 100644 --- a/Lite/Services/RemoteCollectorService.ProcedureStats.cs +++ b/Lite/Services/RemoteCollectorService.ProcedureStats.cs @@ -95,7 +95,7 @@ THEN LTRIM(RTRIM(REPLACE(REPLACE( SUBSTRING( st.text, CHARINDEX(N''CREATE TRIGGER'', st.text) + 15, - CHARINDEX(N'' ON '', st.text + N'' ON '') - CHARINDEX(N''CREATE TRIGGER'', st.text) - 15 + CHARINDEX(N'' ON '', st.text + N'' ON '', CHARINDEX(N''CREATE TRIGGER'', st.text) + 15) - CHARINDEX(N''CREATE TRIGGER'', st.text) - 15 ), N''['', N''''), N'']'', N''''))) ELSE N''trigger_'' + CONVERT(nvarchar(20), s.object_id) END