I\'ve created this stored procedure which dynamically creates the same trigger for all my tables:
USE [MyDatabase]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIE
The error says what the problem is exactly. You are creating a dynamic sql statement to be run all at once by the EXEC statement. GO is a batch separator for use in a command line interface or SSMS. It separates multiple statements to be executed separately. Therefore, you cannot have GO in query statements to be executed by EXEC or sp_executesql.
Simply remove the GO statement, or create two queries to be run by two EXEC statements.