0

So I have an empty target table that I am wanting to copy all the records into from an existing Report table. However, the existing Report table does not have any primary keys, and my new target table does. I want to copy over all the records from the existing Report table that are not duplicates on "Report.field1" and "Report.field2" and they are not NULL in either one as well.

Is there a quick and dirt way to do that? Like:

INSERT INTO target REPORT
ON CONFLICT SKIP
Jasonca1
  • 4,848
  • 6
  • 25
  • 42

1 Answers1

1

Please see: How to avoid duplicate SQL data while executing the INSERT queries without source database

IF not exists(select * from Report where field1 = @field1 and field2 = @field2) and @field1 is not null and @field2 is not null
    INSERT INTO Report (..., ..., ...) 
        VALUES (..., ..., ...)
Marta B
  • 438
  • 2
  • 9
  • There area lot of fields in the original table that I would prefer to not have to write out manually. Is there anyway to structure this statement more concisely and achieve the same results? – Jasonca1 Oct 12 '18 at 17:13
  • https://stackoverflow.com/questions/4526461/converting-select-results-into-insert-script-sql-server – Marta B Oct 12 '18 at 17:16