• Data change.

    I have TableA, it has IDENTITY(1,1) on the PK. I need to clone some of the rows in this table, with only two columns changing. what I decided to was to take a row I need to clone into another table, change the two columns I need to change then put that row back into that table.

    i.e TableA has a row(row1) with 6 columns, and I need to clone this row, but changing only two columns. That mean I will have another row(row1) with the same data as row1 except tow columns.

    So I decided to another table(TableB) with the same structure but exclude ID IDENTITY(1,1), then the take row1 from TableA , put it into TableB, update the two columns of row1 that has to change then put it back to TableA, then it becomes row2, the clone of row1, with two columns changed though. but TableA has IDENTITY(1,1) on the PK, which led me run into errors, saying I'm violating IDENTITY(1,1).

    So I decided to create another table as TableA without IDENTITY(1,1), load the row I want from TableA, update then and so forth.

    Dynamic SQL was the option I thought will be suitable.

    The error I'm getting now is with the loading part.

    SET @InsertSQL = 'INSERT INTO Hosea_tempTable SELECT * FROM ' + @TableName +' WHERE (Product_Id = '''+@Product_Id+''' or Product_Id = '''') AND (Fund_Id = '''+@Fund_Id+''' or Fund_Id is null)';

    ERROR: "Insert Error: Column name or number of supplied values does not match table definition" because TableB doesn't have ID IDENTITY(1,1), which makes it to have 4 columns if TableA had 5 columns including ID IDENTITY(1,1).