我已经对我的 sql 进行了一些调试,但我无法弄清楚我得到的令人抓狂的错误我已经将它缩小到几行,我看不出问题是什么,请有人给我一些帮助。
我收到这个错误
我在这里2 消息 102,级别 15,状态 1,第 1 行 ']' 附近的语法不正确。我在这里3
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'