Here is the actual code I'm running to copy data from one set of tables to another. The table structures are identical.
@dbTable is the new table
@fldList is the list of fields
@tmpTable is the old table.
I'm getting errors because of apostophes in the data.
This is the code used to build the field list:
Code:
SET @runCmd = 'INSERT INTO dbo.' + @dbTable + ' (' + @fldList + ') SELECT ' + @fldList + ' FROM dbo.' + @tmpTable
EXECUTE (@runCmd)
@fldList is the list of fields
@tmpTable is the old table.
I'm getting errors because of apostophes in the data.
This is the code used to build the field list:
Code:
SET @fldList = ''
WHILE (@@FETCH_STATUS = 0)
BEGIN
SET @fldList = @fldList +'['+ @colName+']' + ','
FETCH NEXT FROM cols INTO @colName
END
SET @fldList = LEFT(@fldList,LEN(@fldList)-1)