title: Incorrect syntax near ']'.?
body: <p>I have done some debugging on my sql and I cant figure out the maddening error I am getting I have narrowed it down to a couple of lines which I cant see what the problem is, please someone give me some assistance.</p>
  
  <p>I get this error</p>
  
  <p>I am here2
  Msg 102, Level 15, State 1, Line 1
  Incorrect syntax near
   ']'.
  I am here3</p>
  
  <pre><code> Print 'I am here2'
                          SET IDENTITY_INSERT c365online_script1.dbo.tCompany ON
                          declare @cols2 varchar(max)
                          select @cols2 = (Select Stuff((Select '],[' + C.COLUMN_NAME From INFORMATION_SCHEMA.COLUMNS As C Where C.TABLE_SCHEMA = T.TABLE_SCHEMA And C.TABLE_NAME = T.TABLE_NAME Order By C.ORDINAL_POSITION For Xml Path('')), 1, 2, '') As Columns From INFORMATION_SCHEMA.TABLES As T WHERE T.TABLE_NAME = @tablename)
                          EXEC('INSERT INTO [' + @Destination_Database_Name + '].[dbo].[' + @tablename + '] (' + @cols2 + ']' + ') SELECT ' + @cols2 + ']' + ' FROM [' + @Source_Database_Name + '].[dbo].[' + @tablename + ']');
                           Print 'I am here3'
  </code></pre>