I am too facing the same issue, but not sure about what causes it. When copy paste the in query editor, able to execute it.
Thorough procedure only it failing
Scripts generated from my procedure.
Msg 102, Level 15, State 1, Line 366
Incorrect syntax near 'GO'.
Msg 156, Level 15, State 1, Line 370
Incorrect syntax near the keyword 'CREATE'.
Msg 102, Level 15, State 1, Line 371
Incorrect syntax near 'GO'.
CREATE TABLE dbo.[SolutionAssessmentBPF]
( businessprocessflowinstanceid uniqueidentifier NOT NULL , StatusReasonCode int NULL , TimeZoneRuleVersionNumber int NULL , TraversedPath nvarchar (1250) NULL , UTCConversionTimeZoneCode int NULL , TenantId int NOT NULL , OdsCreatedDate datetime NOT NULL DEFAULT GETUTCDATE() , OdsModifiedDate datetime NOT NULL DEFAULT GETUTCDATE() , OdsStatus tinyint NULL DEFAULT 0 , VersionNumber bigint DEFAULT -1
, CONSTRAINT [PK_SolutionAssessmentBPF] PRIMARY KEY CLUSTERED
(
businessprocessflowinstanceid,TenantId ASC ))
GO
CREATE UNIQUE INDEX [UQX_SolutionAssessmentBPF_bpf_incidentid_OdsStatus] ON [dbo].[SolutionAssessmentBPF] ([bpf_incidentid], [OdsStatus])
GO
CREATE NONCLUSTERED INDEX [NCI_SolutionAssessmentBPF_OdsModifiedDate] ON [dbo].[SolutionAssessmentBPF] ([OdsModifiedDate])
GO
This issue is got fixed after removing GO statement from dynamic SQL generated. Please remove GO statement and any non printable character which is not compatible with windows format. That should fix this kind of issues.