I get the below error
An explicit value for the identity column in table 'c365online_script1.dbo.tProperty' can only be specified when a column list is used and IDENTITY_INSERT is ON.
The problem is with the statement that is dynamically constructed inside the two nested cursors from what I gather it should look something like
INSERT INTO dbo.Table(col1, col2, ...., colN) VALUES(Val1, val2, ...., ValN)
I am however unsure how I would construct the BELOW INSERT statement to resemble the above?.
EXEC('INSERT INTO ' + @Destination_Database_Name + '.dbo.' + @tablename + ' SELECT * FROM ' + @Source_Database_Name + '.dbo.' + @tablename + ' WHERE ' + @Source_Database_Name + '.dbo.' + @tablename + '.CompanyID = ' + @Company_Id)
SET @Counter = 1 -- set the counter to make sure we execute loop only once.
END
use the column listinstead ofSelect *. Simply make your execution query like your example without identity column.