SQL Server 2023-07-29 TSQL Quirks Quirks MustDeclareVariables or that variable already declared Your code has this: 123DECLARE @ErrorMessage NVARCHAR(4000);DECLARE @ErrorSeverity INT;DECLARE @ErrorState INT; And it specifically says @ErrorMessage already declared This is probably a reserved word, change the variable name