1

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.

I get this error

I am here2 Msg 102, Level 15, State 1, Line 1 Incorrect syntax near ']'. I am here3

 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'
4

3 に答える 3

0

私が知る限り、約3つの開き括弧がありません

select @cols2 = (Select Stuff((Select '],[ 

 (' + @cols2 + ']' // -> either [' + @cols2 + ']' or (' + @cols2 + ')'

 + ') SELECT ' + @cols2 + ']'  -- -> either ') SELECT [' + @cols2 + ']'  or ') SELECT (' + @cols2 + ')' 
于 2013-11-01T15:15:05.500 に答える