I am having problems updating a table using INSERT INTO. I have a Temp table (TableA) that I do a bulk upload into. I have a Main table (TableB) that needs to be updated from the Temp table (TableA).
TableA can contain duplicates found in TableB. TableA can also contain duplicates found in itself and I think this is what is causing the issue. The Primary Key for both tables is column1.
I use this method for updating to avoid uploading duplicates into TableB from TableA.
INSERT INTO [dbo].[TableB] ( [column1], [column2], [column3], [column4], [column5] ) SELECT [column1], [column2], [column3], [column4] + ' ' + [column2] + ' ' + [column3], [column5] FROM [dbo].[TableA] LEFT JOIN [dbo].[TableB] ON [dbo].[TableA].[column1] = [dbo].[TableB].[column1] WHERE [dbo].[TableB].[column1] Is Null;
I am still getting an error saying the there is a Key Violation for trying to upload duplicates. I assume that this is happening because TableA has multiple duplicates in itself. How would I go about handling this?