TSQL Quirks

Quirks

  • MustDeclareVariables or that variable already declared

Your code has this:

1
2
3
DECLARE @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