Error when trying to execute a command in sql server
问题 I am using SQL Server 2014 and working on creating views from all the user database on to a Test database. The generated sql statement works fine when run from SSMS but when the execute command tries to run it I get the following error message. SQL Query: DECLARE @SQL NVARCHAR(MAX), @QueryStmt NVARCHAR(MAX) SET @SQL = '' SELECT @SQL = @SQL + CHAR(13) + 'USE ' + QUOTENAME([name]) + '; SELECT @QueryStmt = ''USE TestDWH ''+ CHAR(13) + CHAR(10) + ''GO'' + CHAR(13) + CHAR(10) + ''IF EXISTS (SELECT