I have a query:
DECLARE @str NVARCHAR(max)
SET @str = 'SET QUOTED_IDENTIFIER ON' + CHAR(13)+ CHAR(10) + 'GO' + CHAR(13) + CHAR(10) + 'Select 1 from MyTable'
PRINT @str
EXEC (@str)
It returns an error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near 'GO'.
But if I exec the printed query in a new query editor it works fine.
I am using SQL Server 2014.
ON? – András Váczi Jun 22 '15 at 12:06GO? It is not required in your example. GO implies separate batches and therefore requires dynamic SQL statements to be executed separately. Maybe we can help if you provide your use-case. – Dan Guzman Jun 22 '15 at 12:08