CREATE PROCEDURE [dbo].[ExecuteCommand] @SqlCommand NVARCHAR(MAX)
AS
BEGIN TRY
BEGIN TRAN
  EXEC Sp_ExecuteSql  @SqlCommand
COMMIT TRAN
END TRY 
BEGIN CATCH
  IF CURSOR_STATUS('global','CursorGroup') = 1
  BEGIN
    CLOSE CursorGroup
    DEALLOCATE CursorGroup
  END

  IF CURSOR_STATUS('global','CursorPerson') = 1
  BEGIN
    CLOSE CursorPerson
    DEALLOCATE CursorPerson
  END

  IF CURSOR_STATUS('global','CursorBank') = 1
  BEGIN
    CLOSE CursorBank
    DEALLOCATE CursorBank
  END

  IF CURSOR_STATUS('global','CursorAccount') = 1
  BEGIN
    CLOSE CursorAccount
    DEALLOCATE CursorAccount
  END

  DECLARE @ErrorMessage NVARCHAR(MAX), @ErrorSeverity INT, @ErrorState INT
  SELECT @ErrorMessage = ERROR_MESSAGE()  ,
  @ErrorSeverity = ERROR_SEVERITY(), @ErrorState = ERROR_STATE()
  ROLLBACK TRANSACTION
  INSERT INTO dbo.TransferBetweenFinancialYearsError(SqlCommand,ErrorMessage)
  VALUES(@SqlCommand, @ErrorMessage)
  RAISERROR (@ErrorMessage, @ErrorSeverity, @ErrorState)
END CATCH

